美文网首页程序员
SpringBoot2 pagehelper 使用笔记

SpringBoot2 pagehelper 使用笔记

作者: yingjunchen | 来源:发表于2018-10-22 20:00 被阅读200次

pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>1.2.5</version>
</dependency>

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

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

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

打印的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 使用笔记

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