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& ...
随机推荐
- Codeforces Round 890 (Div. 2)
Tales of a Sort 题解 找到最大的能够产生逆序对的数即可 暴力\(O(n^2)\)枚举即可 const int N = 2e5 + 10, M = 4e5 + 10; int n; in ...
- 全网最适合入门的面向对象编程教程:60 Python面向对象综合实例-传感器数据实时绘图器
全网最适合入门的面向对象编程教程:60 Python 面向对象综合实例-传感器数据实时绘图器 摘要: 本文将结合之前内容实现模拟一个传感器系统软件,包括三个线程:传感器线程生成数据并通过串口发送给主机 ...
- flutter安装过程中 flutter doctor 出现错误 cmdline-tools component is missing
进入Android studio的settings添加tool工具
- DA14531芯片固件逆向系列(1)-固件加载和逆向分析
首发于先知论坛 https://xz.aliyun.com/t/9185 前言 本文介绍逆向DA14531芯片的固件,并介绍一些辅助自动化分析的脚本的实现.DA14531是Dialog公司研制的蓝牙芯 ...
- .net delegate 万能适配
遇到一个技术点,记一下,.net 有一个 Delegate Marshall.GetDelegateForFunctionPointer(IntPtr ptr, Type t) 用来将内存地址映射为一 ...
- Docker 部署数据可视化 Superset 3.0.0 深度汉化并配置元数据存储为 Postgres
services: postgres: image: postgres:14.10 container_name: postgres hostname: postgres environment: P ...
- K8S学习笔记之卸载K8S集群
阅读目录 0x00 概述 0x01 操作 0x00 概述 有时候需要卸载已安装在本机的K8S服务和服务,本文卸载的K8S面向使用kubeadm或者二进制方法安装的,不涉及使用rpm包安装的集群: 主 ...
- IntelliJ IDEA 导入项目后出现非法字符解决方法
1.Ctrl+Alt+S进入设置页面如图,更改为UTF-8 2.Ctrl+Alt+S进入设置页面如图,在箭头所指的位置填上 -encoding UTF8 3.清除文件中的BOM特殊不可见字符 选择项目 ...
- Debian 9.5 解决中文显示乱码
一.首先检查LOCALE情况 说明:DEBIAN因为基于GNU所以,对不同地域进行了不同的包支持,以LOCALE形式存在. 1.启动终端 #apt-get install locales 2.重新配置 ...
- vue3项目中报错:Unexpected mutation of "xxx" prop
vue3 中element 弹窗绑定需要通过v-model,这个时候父级会传个dialogVisible(boolean值)过来,结果会报eslint的错. Unexpected mutation o ...

