本文共 1370 字,大约阅读时间需要 4 分钟。
pom.xml引入jar
org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.0 com.baomidou mybatis-plus-boot-starter 3.0.6
#application.properties配置文件中设置MybatisPlus的mapper文件扫描
mybatis-plus.mapper-locations=classpath*:扫描包下的路径/*Mapper.xml//我的路径是mybatis-plus.mapper-locations=classpath*:com/zgf/springboot03loggin/mapper/xml/*Mapper.xml
mapper层的接口继承BaseMapper泛型类传递一个需要执行增删改查的实体类,
@Mapperpublic interface IPhoneMapper extends BaseMapper <实体类> { } 实体类>
entity类代码
//自动封装实体类数据@Data//标识使用的数据库表@TableName("book")public class BookEntity { //自动映射数据库主键 @TableId(type = IdType.AUTO) private int id; //@TableField("数据库列名") private String name; private String author; private int tid; private double Bmoney;}
Service层
public interface IBookService extends IService{ }
service的实现层
public class IBookServiceImpl extends ServiceImplimplements IBookService { }Controller层```java@Controllerpublic class BookController { @Resource(name = "iBookServiceImpl") IBookService iBookService; @RequestMapping("/select") @ResponseBody public String select(){ return JSON.toJSONString(iBookService.list()); }}
转载地址:http://smqzi.baihongyu.com/