1、pom依赖
com.github.pagehelper
pagehelper-spring-boot-starter
1.2.3
2、分页配置application.properties
pagehelper.helper-dialect=mysql
pagehelper.reasonable=true
pagehelper.support-methods-arguments=true
pagehelper.params=count=countSql
1)其中pagehelper.reasonable这个属性含义是分页参数合理化,3.3.0以上版本可用
当启用合理化时,如果pageNum>pageSize,默认会查询最后一页的数据。禁用合理化后,当pageNum>pageSize会返回空数据
2)pagehelper.support-methods-arguments
支持通过 Mapper 接口参数来传递分页参数,在开启分页时直接将实体类传入,pageHelper会自动根据 pagehelper.params中设定的参数来进行开启分页的参数映射,例如设置pagehelper.params=pageNum=start;pageSize=limit 则将对象传入startPage(Object o)中时,会自动配置pageNum为start,pageSize为limit
3)pagehelper.params=count=countSql
支持上述的配置的参数配置
3、在原有查询前加一行
PageHelper.startPage(0 , 1); 两个参数类似mysql的limit
@RequestMapping("findByMedicalIDAndRecordType")
public PageInfo> findByMedicalIDAndRecordType(@RequestParam Map map){
PageHelper.startPage(0 , 1);
List> list=checkApplyService.findByMedicalIDAndRecordType(map);
//得到分页的结果对象
PageInfo> personPageInfo = new PageInfo<>(list);
return personPageInfo;
}
4、测试:
结果输出
{
"pageNum":1,
"pageSize":1,
"size":1,
"startRow":1,
"endRow":1,
"total":2,
"pages":2,
"list":[
{
"isUrgent":0,
"creationTime":"2020-05-19T01:59:07.000+0000",
"recordType":1,
"num":1,
"registId":2,
"objective":"121313",
"checkOperId":"",
"result":"",
"itemId":200,
"resultOperId":"",
"doctorId":"402880ed71f6e7070171f814c89f000c",
"name":"121121",
"medicalId":"402880ed722698dc017226aa94170000",
"id":2,
"position":"头",
"state":1
}
],
"prePage":0,
"nextPage":2,
"isFirstPage":true,
"isLastPage":false,
"hasPreviousPage":false,
"hasNextPage":true,
"navigatePages":8,
"navigatepageNums":[
1,
2
],
"navigateFirstPage":1,
"navigateLastPage":2,
"firstPage":1,
"lastPage":2
}