springboot2 pagehelper 使用笔记

作者:cnJun
博客专栏:
https://www.cnblogs.com/cnJun/

pom.xml


    org.springframework.boot
    spring-boot-starter-parent
    2.0.4.RELEASE
     



    com.github.pagehelper
    pagehelper-spring-boot-starter
    1.2.5

引入的jar包必须是要pagehelper-spring-boot-starter如果单独引入pagehelper的话,分页会不成功,现在导入的结果如下:

使用时PageHelper.startPage(pageNum, pageSize)一定要放在列表查询上面,这样在查询时会查出相应的数据量且会查询出总数,像图中总数量有两条,page里面查询出来了是2,但list只查出了1条,因为我传的分页是pageNo=1,pageSize=1

PageHelper.startPage(pageNum, pageSize);
List systemUserList = systemUserMapper.page(find);
PageInfo page = new PageInfo<>(systemUserList);

springboot2 pagehelper 使用笔记_第1张图片

打印的sql如下所示

Preparing: SELECT count(0) FROM (SELECT su.id, su.name, su.nick_name, su.email, su.phone, su.sex, su.fail_num, su.status, su.create_time, su.update_time, GROUP_CONCAT(sr.name) AS rolesName FROM SYSTEM_USER su, system_user_role sur, system_role sr WHERE su.id = sur.user_id AND sur.role_id = sr.id GROUP BY su.id) table_count 
Parameters: 
Total: 1
Preparing: SELECT su.id, su.name, su.nick_name, su.email, su.phone, su.sex, su.fail_num, su.status, su.create_time, su.update_time, group_concat(sr.name) as rolesName FROM SYSTEM_USER su, system_user_role sur, system_role sr WHERE su.id = sur.user_id AND sur.role_id = sr.id GROUP BY su.id LIMIT ? 
Parameters: 1(Integer)
Total: 1

你可能感兴趣的:(springboot2 pagehelper 使用笔记)