Springboot 3.x 使用PageHelper实现MyBatis分页查询
开发环境
SpringBoot 3.0.1
Maven 工程
JDK OpenJdk 17.0.6
引入pom依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.7</version>
</dependency>
注意: Springboot 3.x 版本必须引用1.4.6版本以上,否则无效 GitHub官方描述
设置 application.yml
#MyBatis分页工具
pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-arguments: true
params: count=countSql
代码展示
PageQueryMoDetDTO
/**
* 分页查询查询德育学分明细DTO
* @Author Hmi
* @Date 2023/7/31 8:36
*/
@Data
public class PageQueryMoDetDTO implements Serializable {
/**
* 学号
*/
private String stuid;
/**
* 状态值 0-封禁 1-正常
*/
private Integer status;
/**
* 页码
*/
private int page;
/**
* 每页数据量
*/
private int pageSize;
// ... 这里使用了lombok简化了get/set方法
}
MoralDetailsController
@GetMapping("/pageQueryMoDet")
@Operation(summary = "分页查询数据详情")
public Result queryMoDet(PageQueryMoDetDTO pageQueryMoDetDTO) {
log.info("分页查询数据详情:{}", pageQueryMoDetDTO);
return moralDetailsServer.pageQueryMoDet(pageQueryMoDetDTO);
}
MoralDetailsMapper
List<Moraldetails> pageQueryMoDet(PageQueryMoDetDTO pageQueryMoDetDTO);
MoralDetailsMapper.xml
<select id="pageQueryMoDet" resultType="Moraldetails">
select * from moraldetails
<where>
stuid = #{stuid}
<if test="status != null">
and status = #{status}
</if>
order by create_time desc
</where>
</select>
MoralDetailsServer
Result pageQueryMoDet(PageQueryMoDetDTO pageQueryMoDetDTO);
MoralDetailsServerImpl
public Result pageQueryMoDet(PageQueryMoDetDTO pageQueryMoDetDTO) {
PageHelper.startPage(pageQueryMoDetDTO.getPage(), pageQueryMoDetDTO.getPageSize());
List<Moraldetails> list = moralDetailsMapper.pageQueryMoDet(pageQueryMoDetDTO);
PageInfo<Moraldetails> pageInfo = new PageInfo<Moraldetails>(list);
return Result.ok(pageInfo);
}
运行调试
使用ApiFox或其他的Api工具发送请求
服务器输出运行日志
成功获取分页查询数据
{
"code": 200,
"success": true,
"msg": "操作成功",
"result": {
"total": 984,
"list": [
{
"id": 1005,
"stuid": "215534999",
"name": null,
"particulars": "ceshiceshi",
"type": 0,
"changeValues": 100,
"way": 3,
"operator": "215534120",
"status": 0,
"createTime": "2023-06-17 19:15:19",
"updateTime": "2023-06-23 20:27:47",
"createUser": "",
"updateUser": ""
},
{
"id": 5,
"stuid": "215534999",
"name": null,
"particulars": "Navicat Cloud could not connect ",
"type": 0,
"changeValues": 15,
"way": 1,
"operator": "215534120",
"status": 0,
"createTime": "2023-06-10 17:53:05",
"updateTime": "2023-06-23 20:37:28",
"createUser": "",
"updateUser": ""
},
{
"id": 7,
"stuid": "215534999",
"name": null,
"particulars": "The Main Window consists of several ",
"type": 0,
"changeValues": 7,
"way": 5,
"operator": "215534120",
"status": 0,
"createTime": "2023-06-10 17:53:05",
"updateTime": "2023-06-23 20:37:05",
"createUser": "",
"updateUser": ""
},
{
"id": 21,
"stuid": "215534999",
"name": null,
"particulars": "It wasn’t raining when Noah built the ark. ",
"type": 1,
"changeValues": 14,
"way": 4,
"operator": "215534120",
"status": 0,
"createTime": "2023-06-10 17:53:05",
"updateTime": "2023-06-23 20:27:47",
"createUser": "",
"updateUser": ""
},
{
"id": 23,
"stuid": "215534999",
"name": null,
"particulars": "Success consists of going from ",
"type": 1,
"changeValues": 8,
"way": 3,
"operator": "215534120",
"status": 0,
"createTime": "2023-06-10 17:53:05",
"updateTime": "2023-06-23 20:27:47",
"createUser": "",
"updateUser": ""
}
],
"pageNum": 1,
"pageSize": 5,
"size": 5,
"startRow": 1,
"endRow": 5,
"pages": 197,
"prePage": 0,
"nextPage": 2,
"isFirstPage": true,
"isLastPage": false,
"hasPreviousPage": false,
"hasNextPage": true,
"navigatePages": 8,
"navigatepageNums": [
1,
2,
3,
4,
5,
6,
7,
8
],
"navigateFirstPage": 1,
"navigateLastPage": 8
},
"timestamp": 1691668424792
}
Springboot 3.x 使用PageHelper实现MyBatis分页查询的更多相关文章
- springboot结合mybatis使用pageHelper插件进行分页查询
1.pom相关依赖引入 <dependencies> <dependency> <groupId>org.springframework.boot</grou ...
- SpringBoot-07:SpringBoot整合PageHelper做多条件分页查询
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客讲述如何在SpringBoot中整合PageHelper,如何实现带多个条件,以及PageInfo中的 ...
- SpringBoot整合PageHelper做多条件分页查询
https://yq.aliyun.com/articles/619586 本篇博客讲述如何在SpringBoot中整合PageHelper,如何实现带多个条件,以及PageInfo中的属性的中文解释 ...
- mybatis分页查询需要注意的问题
一般对mybatis的分页查询的关键代码就两行: #currentPage代表当前页,pageSize代表每页的行数 PageHelper.startPage(currentPage, pageSiz ...
- spring boot +mybatis分页查询
这是spring boot集合mybatis的分页查询. pom依赖: <!-- 分页插件 --> <dependency> <groupId>com.github ...
- Mybatis 分页查询
该篇博客记录采用pagehelper分页插件实现Mybatis分页功能 一.依赖 pom.xml <!-- pagehelper --> <dependency> <gr ...
- Mybatis分页查询total中的坑
写在前面 今天用mybatis进行分页查询,大家应该都用过pageHelper这个插件,但是在计算总的数据数的时候,page.getTotal()总是返回0,要么就是返回pageSize(),今天给大 ...
- springmvc+spring+mybatis分页查询实例版本1,ver1.0
无聊做做看看,几乎没有怎么仔细做过这方面的,总是以为很简单,想想就会,实际做起来结合工作经验感觉还是挺有收获的,可以用在自己的项目上 第一版本思路:框架使用ssm,这个无所谓,采用分页语句查询指定页面 ...
- JAVA入门[10]-mybatis分页查询
1.添加分页插件 在mybatis-generator-config.xml添加plugin节点: <plugin type="org.mybatis.generator.plugin ...
- mybatis分页查询的万能模板
分页查询项目里太多了,而这种分页查询,在mybatis里面的配置几乎一模一样,今天就整理一个比较好和实用的模板,供以后直接Ctrl+C <select id="queryMember& ...
随机推荐
- HarmonyOS Next 集成支付宝SDK后无法在模拟器上安装调试的问题
之前使用模拟器调试都正常,在集成支付宝SDK后,同事说在模拟器上无法安装调试,因为真机资源不够,模拟器不能用实在耽误事,所以就花了点时间研究一下. 报错原因 官方文档的解释 根据文档的说明,应该是cp ...
- 反编译wx小程序遇到的问题
怎么反编译就不说了,有很多文章,推荐两个 http://t.csdnimg.cn/DrvBZ http://t.csdnimg.cn/NOEys 下面开始说问题 _typeof3 is not a f ...
- \r,\n,\r\n的前世今生
前情 最近在逛论坛的时候遇到有人在提问题,为什么\n在苹果手机上不换行,我以前有网上看到过文章,是因为各系统的解析不同,需要使用\r\n来做兼容,自己虽然知道怎么解决,但是不知具体原因,今特来详细了解 ...
- 鸿蒙应用开发从入门到入行 - 篇1:HarmonyOS介绍——带你深入理解鸿蒙特性
鸿蒙应用开发从入门到入行 第一天 - HarmonyOS介绍 导读:在本篇文章里,您将了解到HarmonyOS是什么,以及有哪些振奋人心的特性.并且猫林老师会在本篇文章里给出结论:鸿蒙必能蚕食安卓份额 ...
- vue3 + vite 报错处理
TypeError: vite.defineConfig is not a function 执行命令:npm install @vitejs/plugin-vue -D config里面配置代码: ...
- function keyword is non-standard. Delete it.
SC2112 – ShellCheck Wiki See this page on GitHub function keyword is non-standard. Delete it. Proble ...
- iaas,saas,paas,daas区别:
iaas,saas,paas,daas区别: Iaas(Infrastructure as a server):基础设施即服务,是基础层.PaaS(Platform as a Server):平台即服 ...
- OkHttp实现延时重试
本文主要应用了OkHttp的Interceptor来实现自定义重试次数 虽然OkHttp自带retryOnConnectionFailure(true)方法可以实现重试,但是不支持自定义重试次数,所以 ...
- Spring事务管理深度解析-从实践到原理
事务管理在系统开发中是不可缺少的一部分,Spring提供了很好事务管理机制 分类 主要分为编程式事务和声明式事务两种. 编程式事务 是指在代码中手动的管理事务的提交.回滚等操作,代码侵入性比较强,如下 ...
- 大型IM工程重构实践:企业微信Android端的重构之路
本文由腾讯技术yeconglu分享,原题"企业微信大型Android系统重构之路",下文进行了排版和内容优化等. 1.引言 企业微信本地部署版(下文简称为本地版)是从2017年起, ...

