• springboot2 pagehelper 使用笔记


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

    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
  • 相关阅读:
    【leetcode】38. Count and Say
    【leetcode】132. Palindrome Partitioning II
    New Concept English three (56)
    New Concept English three (55)
    New Concept English three (54)
    listening 1
    New Concept English three (53)
    BEC translation exercise 4
    New Concept English three (52)
    MBA 工商管理课程-风险型决策方法
  • 原文地址:https://www.cnblogs.com/jpfss/p/10782405.html
Copyright © 2020-2023  润新知