springboot使用pagehelper

自己写的用户系统项目需要加个分页,之前都是用现成的,或者使用在sql里面拼接分页查询,这次任务紧急想直接找个包实现吧,找了很多博客看了都不行啊,不知道为啥,最后还是找了之前maven使用的包才行,简单记录如下

gradle引入包

   // https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper-spring-boot-starter
    implementation group: 'com.github.pagehelper', name: 'pagehelper-spring-boot-starter', version: '1.4.1'

接着去bootstrap.yml添加配置

pagehelper:
  helperDialect: mysql
  reasonable: true
  supportMethodsArguments: true
  params: count=countSql

最后serviceImpl就可以直接用了

// 需先定义查询的分页参数
 PageHelper.startPage(2, 3);
 // 一个普通的查询在其后,这个就会被自动加上分页
 List<UserDo> userDos = userDao.findAll();
 // 获取分页信息
 PageInfo<UserDo> pageInfo = new PageInfo<>(userDos);

查看sql语句,如下图分页成功
在这里插入图片描述

posted @   蜗牛使劲冲  阅读(8)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示