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& ...
随机推荐
- mysql基础之增删改查
标签: mysql 增加数据 -- 增加数据 use myblog; insert into users(username, `password`, realname) values('zhangsa ...
- idea中yaml文件中文乱码问题解决
idea打开yaml,或是properties文件,出现中文乱码. 解决步骤: 打开notepad++ ,新建iso-8859-1编码的空文件 将乱码文件通过notepad++直接打开,把正常显示的代 ...
- 跨平台交叉编译 Native AOT
如何将.NET 应用程序发布到鸿蒙上,肯定是很多人感兴趣的话题,目前.NET完全具备可以在OpenHarmony系统上运行的能力,.NET 现在有很多选项CoreCLR.Mono和NativeAOT. ...
- 关于 Span 的一切:探索新的 .NET 明星: 4. Span<T> 和 Memory<T> 是如何与 .NET 库集成的?
4. Span<T> 和 Memory<T> 是如何与 .NET 库集成的? 1. Span<T> 是什么? 2. Span<T> 是如何实现的? 3. ...
- Chaincode installation on peer0.org1 has failed
v1.4 版本执行 ./byfn.sh up时,报如下错误 Error: error getting chaincode deployment spec for mycc: error getting ...
- Qt数据库应用6-数据图文混排
一.前言 除了能够打印基本的文字信息数据到pdf和纸张,越来越多的应用需求还要求能够导出图片,并且要支持图文混排,相当于doc文档类似,当然也不会是太复杂的,类似于打印报表一样,有表格形式的文字描述, ...
- Qt编写的项目作品9-音频综合应用示例
一.功能特点 自动计算音频振幅,绘制音频振幅曲线和音频数据曲线. 支持音频录制,可选音频输入设备.采样频率.通道等参数,Qt5默认保存wav格式,Qt6默认保存mp3格式,Qt6可选wma.aac等格 ...
- findHomography()函数详解
indHomography: 计算多个二维点对之间的最优单映射变换矩阵 H(3行x3列) ,使用最小均方误差或者RANSAC方法 函数功能:找到两个平面之间的转换矩阵. Mat cv::findHom ...
- 史上最通俗Netty入门长文:基本介绍、环境搭建、动手实战
原作者江成军,原题"还在被Java NIO虐?该试试Netty了",收录时有修订和改动. 1.阅读对象 本文适合对Netty一无所知的Java NIO网络编程新手阅读,为了做到这一 ...
- (.net core)Kong网关的使用
一.优势: 提供统一的 API 管理,简化流量控制.负载均衡.安全性控制等工作. 有可视化界面可操作,支持高度 可扩展性,可以通过插件来扩展功能. 在 微服务架构 中表现优异,支持多种协议和高并发场景 ...

