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& ...
随机推荐
- vue 创建一个项目
1.npm init -y 2.vue create 名称 3.manuall select features [手动配置v2,v3] 4.选版本 5 6 启动:npm run serve
- StarBlog博客Vue前端开发笔记:(1)准备篇
前言 之前在[基于.NetCore 开发博客项目 StarBlog - (32) 第一期完结]里说到 StarBlog 的 Vue 前端系列已经写好了 本来打算后面再发的,不过最近有点懒没去写新的文章 ...
- 关于Popup的小坑坑
在做一个自定义的输入搜索框,用textbox+popup来实现.其中有一个小需求,当textbox激活并且没有文本输入的时候,也要显示popup.很自然的想到了使用IsKeyboardFocusedC ...
- 腾讯云对象存储联合DataBend云数仓打通数据湖和数据仓库
随着数字化进程不断深入,数据呈大规模.多样性的爆发式增长.为满足更多样.更复杂的业务数据处理分析的诉求,湖仓一体应运而生.在Gartner发布的<Hype Cycle for Data Mana ...
- Flutter null safety 无法运行
Flutter空安全问题 在pub上有一些库导入之后无法运行,这是因为健全的空安全 解决方法 1.在命令行中添加参数 flutter run --no-sound-null-safety 2.在IDE ...
- mongodb和spring集成中MongoTemplate的总结是使用方法
基础实体类@Document(collection="person") class Person{ String id; String name; int age; public ...
- 得物从0到1自研客服IM系统的技术实践之路
本文由得物技术王卫强分享,为了更好的阅读体验,有较多的内容修订和排版优化. 一.引言 客服IM的核心业务其实就是在线沟通,客服IM的好处是使得客服与用户通过实时沟通的方式可以在最短的时间内帮助用户解决 ...
- 开源即时通讯IM框架 MobileIMSDK v6.2 发布
一.更新内容简介 本次更新为次要版本更新,进行了若干优化(更新历史详见:码云 Release Nodes).可能是市面上唯一同时支持 UDP+TCP+WebSocket 三种协议的同类开源IM框架. ...
- Python_图片对比问题汇总
问题一. raise OSError(f"cannot write mode {im.mode} as JPEG") from eOSError: cannot write mod ...
- Solution -「Gym 101630J」Journey from Petersburg to Moscow
\(\mathscr{Description}\) Link. 给定含有 \(n\) 个点 \(m\) 条边的带权无向图,一条路径的长度定义为其中前 \(k\) 大的边权和,求 \(1\) 到 ...

