springboot引入mytais-plus使用
导入依赖,进行属性配置,创建对应pojo,service,mapper,controller
导入相关依赖
<!--导入mybatis-plus启动器-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>2.3</version>
</dependency>
<!--//连接数据库-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
对应的propertites配置:
server.port=8379
mybatis-plus.global-config.db-column-underline=true
mybatis-plus.global-config.capital-mode=true
mybatis-plus.global-config.map-underscore-to-camel-case=true
spring.datasource.url=jdbc:mysql://localhost:3306/kai?useUnicode=true&characterEncoding=UTF-8&allowPublicKeyRetrieval=true&useSSL=false&&serverTimezone=UTC
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
pojo层,service层,mapper层
//pojo
@TableName("people")
public class people {
private static final long serialVersionUID = 1L;
@TableId
private Integer id;
private String name;
private Integer age;
private String hobby;
private Date creatTime;
//mapper
@Mapper
public interface PeopleMapper extends BaseMapper<people> {
}
//service
@Service
public class peopleServiceImpl extends ServiceImpl<PeopleMapper, people> implements peopleService {
}
//service的接口
public interface peopleService extends IService<people> {
}
controller层接口调用测试
@RestController
@RequestMapping("ssss")
public class peopleControlller {
private final peopleService peopleService;
public peopleControlller(com.example.springboottest.service.peopleService peopleService) {
this.peopleService = peopleService;
}
@GetMapping
public people getPeople(@RequestParam("id") int id){
people people = peopleService.selectById(id);
return people;
}
@GetMapping("pages")
public Page<people> getPeoples(@RequestParam(name="page",required = false,defaultValue = "1") int page,
@RequestParam(name="pageNo",required = false ,defaultValue = "3") int pageNo){
return peopleService.selectPage(new Page<>(page,pageNo));
}
}

浙公网安备 33010602011771号