简单粗暴:SpringBoot+PageHelper插件实现自动分页

第一步:

导入MAVEN依赖
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.12</version>
        </dependency>

第二步:

yml配置文件新增以下配置
    pagehelper:
      helperDialect: mysql
      reasonable: true
      supportMethodsArguments: true
      params: count=countSql

第三步:代码中使用

     PageHelper.startPage(getPageNum(),getPageSize());//手动开启分页


     List<GameLtv> gameLtvs = gameLtvMapper.selectGameLtvList(param);//执行查询


     PageInfo<GameLtv> pageInfo = new PageInfo<GameLtv>(gameLtvs);//获取分页情况


     int total = pageInfo.getTotal();//获取分页数据-总记录数

补充1.Mapper的写法  (正常写,没有什么需要特殊注意的)

补充2.请求参数实体的写法(字段名尽量用 pageNum 和 pageSize )

补充3.Mapper.xml (正常写,没有什么需要特殊注意的)

发布了4 篇原创文章 · 获赞 3 · 访问量 161

猜你喜欢

转载自blog.csdn.net/q2450751976/article/details/103945098