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& ...
随机推荐
- manim边做边学--圆柱体
Cylinder是Manim中用于创建圆柱体对象的类. Cylinder类在制作数学.物理或工程领域的动画时,可用于以下的场景中: 演示几何概念:使用Cylinder类创建圆柱体,并通过改变其参数和方 ...
- 2020-2021 ACM-ICPC Brazil Subregional Programming Contest
A. Sticker Album 你想要得到\(n\)张贴纸,每包礼物中等概率出现 \([A,B]\)范围内数量的贴纸,求需要买多少包礼物才能至少获得\(n\)张贴纸的期望次数 \(1 \leq n ...
- 将ipynb文件转成pdf
本文内容:将GitHub上ipynb源码格式的书籍转成pdf 应用场景:GitHub上某些书籍按章节使用ipynb格式存储 (Jupyter创建了一种良好的交互方式,即将程序说明和代码放在同一个文档中 ...
- 基于云主机的ModelArts模型训练实践,让开发环境化繁为简
本文分享自华为云社区<[开发者空间实践]云主机安装Docker并制作自定义镜像在ModelArts平台做模型训练>,作者: 开发者空间小蜜蜂. 1.1 案例介绍 在AI业务开发以及运行的过 ...
- python多版本
1.分别下载并安装两个版本的python 2.去安装的文件夹中将python.exe 和pythonw.exe改名加上版本号 3.将python.exe文件目录和当前目录下的Scripts目录都加到用 ...
- NoSQL 述评
作为主库的 nosql 只有 CockroachDB.TiKV 以及 MongoDB(从4.0后事务似乎可用了),CockrouchDB 已经收费,另外 YugabyteDB 也可选,但大家的反馈都不 ...
- Ubuntu下安装和开启telnet
安装命令如下 sudo apt-get install openbsd-inetd sudo apt-get install telnetd sudo /etc/init.d/openbsd-in ...
- 基于Xxl-Job,dataX设计的数据同步和可视化任务编排工具
使用vue3对xxl-job进行重构,并集成datax工具实现不同数据源的数据同步,支持glue模式,并新增存储过程调用,api任务调度和可视化任务编排,支持单任务-单任务串并联,单任务-任务集串并联 ...
- 使用Maven客户端从Maven中心仓库下载到本地的jar包的默认存储位置及远程仓库
从Maven中心仓库下载到本地的jar包的默认存放在"${user.home}/.m2/repository"中,${user.home}表示当前登录系统的用户目录(如" ...
- 开源轻量级IM框架MobileIMSDK的鸿蒙NEXT客户端库已发布
一.基本介绍 MobileIMSDK-鸿蒙端是一套基于鸿蒙Next(纯血鸿蒙)系统的IM即时通讯客户端库: 1)超轻量级(编译后库文件仅50KB).无任何第3方库依赖(开箱即用): 2)纯ArkTS编 ...