pom.xml引入jar
<!-- mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
<!--mybatis-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.6</version>
</dependency>
#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泛型类传递一个需要执行增删改查的实体类,
@Mapper
public 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<BookEntity> {
}
service的实现层
public class IBookServiceImpl extends ServiceImpl<IBookMapper, BookEntity> implements IBookService {
}
Controller层
```java
@Controller
public class BookController {
@Resource(name = "iBookServiceImpl")
IBookService iBookService;
@RequestMapping("/select")
@ResponseBody
public String select(){
return JSON.toJSONString(iBookService.list());
}
}