美文网首页
14 springboot+mybatis集成pageHelpe

14 springboot+mybatis集成pageHelpe

作者: wqjcarnation | 来源:发表于2020-05-20 09:12 被阅读0次

1、pom依赖

        <!-- 分页插件 -->
        <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper-spring-boot-starter</artifactId>
        <version>1.2.3</version>
        </dependency>

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<Map<String, Object>> findByMedicalIDAndRecordType(@RequestParam Map<String,Object> map){
    PageHelper.startPage(0 , 1);
    List<Map<String, Object>> list=checkApplyService.findByMedicalIDAndRecordType(map);
    //得到分页的结果对象
    PageInfo<Map<String, Object>> 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
}

相关文章

网友评论

      本文标题:14 springboot+mybatis集成pageHelpe

      本文链接:https://www.haomeiwen.com/subject/ywtgohtx.html