Springboot整合Mybatis分页插件PageHelpe
2021-02-24 本文已影响0人
c_gentle
一、引入依赖
<!-- pagehelper 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
二、yml进行配置
#pagehelper配置
pagehelper:
helper-dialect: mysql
params: count=countSql
reasonable: true
supportMethodsArguments: true
三、方法使用
PageHelper.startPage(page, limit)会对下次查询进行分页,不影响原查询效果。
/**
* 分页查询老师信息
*
* @param
* @return
*/
@ApiOperation(value = "查询老师分页")
@GetMapping("/{page}/{limit}")
public R getTeacherPage(
@ApiParam(name = "page", value = "当前页数", required = true)
@PathVariable Integer page,
@ApiParam(name = "limit", value = "当前页数据", required = true)
@PathVariable Integer limit
) {
PageHelper.startPage(page, limit);
List<EduTeacher> list = eduTeacherService.getAllEduTeacher();
PageInfo pageInfo = new PageInfo<EduTeacher>(list);
return R.ok().data("item", pageInfo);
}