当前位置:网站首页>12、分页插件
12、分页插件
2022-08-04 05:24:00 【猿 白】
12、分页插件
limit index,pageSize
pageSize:每页显示的条数
pageNum:当前页的页码
index:当前页的起始索引,index=(pageNum-1)*pageSize
count:总记录数
totalPage:总页数
totalPage = count / pageSize;
if(count % pageSize != 0){
totalPage += 1;
}
pageSize=4,pageNum=1,index=0 limit 0,4
pageSize=4,pageNum=3,index=8 limit 8,4
pageSize=4,pageNum=6,index=20 limit 8,4
效果:
首页 上一页 2 3 4 5 6 下一页 末页
12.1、分页插件的使用步骤
①添加依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.2.0</version>
</dependency>
配置分页插件
在MyBatis的核心配置文件中配置插件
<plugins>
<!--设置分页插件-->
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
- 在查询功能之前使用PageHelper.startPage(int pageNum, int pageSize)开启分页功能
pageNum:当前页的页码
pageSize:每页显示的条数
- 在查询获取list集合之后,使用PageInfo<T> pageInfo = new PageInfo<>(List<T> list, int navigatePages)获取分页相关数据
list:分页之后的数据
navigatePages:导航分页的页码数
- 分页相关数据
PageInfo{
pageNum=8, pageSize=4, size=2, startRow=29, endRow=30, total=30, pages=8,
list=Page{count=true, pageNum=8, pageSize=4, startRow=28, endRow=32, total=30,
pages=8, reasonable=false, pageSizeZero=false},
prePage=7, nextPage=0, isFirstPage=false, isLastPage=true, hasPreviousPage=true,
hasNextPage=false, navigatePages=5, navigateFirstPage4, navigateLastPage8,
navigatepageNums=[4, 5, 6, 7, 8]
}
pageNum:当前页的页码
pageSize:每页显示的条数
size:当前页显示的真实条数
total:总记录数
pages:总页数
prePage:上一页的页码
nextPage:下一页的页码
isFirstPage/isLastPage:是否为第一页/最后一页
hasPreviousPage/hasNextPage:是否存在上一页/下一页
navigatePages:导航分页的页码数
navigatepageNums:导航分页的页码,[1,2,3,4,5]
测试:
public class PageTest {
@Test
public void testPage(){
SqlSession sqlSession = sqlSessionUtil.getSqlSession();
EmpMapper mapper = sqlSession.getMapper(EmpMapper.class);
// 查询功能之前开启分页功能
Page<Object> pages = PageHelper.startPage(1, 4);
List<Emp> emps = mapper.selectByExample(null);
// 查询功能之后可以获取分页相关的所有数据
PageInfo<Emp> empPageInfo = new PageInfo<>(emps, 5);
emps.forEach(System.out::println);
System.out.println(empPageInfo);
}
// PageInfo{
// pageNum=1, pageSize=4, size=4,
// startRow=1, endRow=4, total=42,
// pages=11,
// list=Page{count=true, pageNum=1, pageSize=4, startRow=0, endRow=4, total=42, pages=11, reasonable=false, pageSizeZero=false}[Emp{empId=1, empName='张三', age=18, gender='男', deptId=1}, Emp{empId=2, empName='李四', age=19, gender='男', deptId=2}, Emp{empId=3, empName='王五', age=20, gender='女', deptId=1}, Emp{empId=4, empName='小花', age=18, gender='女', deptId=2}],
// prePage=0, nextPage=2, isFirstPage=true, isLastPage=false,
// hasPreviousPage=false, hasNextPage=true,
// navigatePages=5, navigateFirstPage=1, navigateLastPage=5, navigatepageNums=[1, 2, 3, 4, 5]}
}
边栏推荐
- Turn: Management is the love of possibility, and managers must have the courage to break into the unknown
- How to keep the source code confidential in the development under the burning scenario
- Towards Real-Time Multi-Object Tracking (JDE)
- 注意!软件供应链安全挑战持续升级
- C专家编程 第5章 对链接的思考 5.1 函数库、链接和载入
- Programming hodgepodge (4)
- 嵌入式系统驱动初级【3】——字符设备驱动基础中_IO模型
- Redis common interview questions
- 2023年PMP考试会用新版教材吗?回复来了!
- OpenGL绘制圆
猜你喜欢
Shocked, 99.9% of the students didn't really understand the immutability of strings
npm报错Beginning October 4, 2021, all connections to the npm registry - including for package installa
leetcode 12. Integer to Roman numeral
System design. Seckill system
day13--postman interface test
少年成就黑客,需要这些技能
擎朗智能全国研发创新中心落地光谷:去年曾获2亿美元融资
Delphi-C端有趣的菜单操作界面设计
深度学习21天——准备(环境配置)
el-Select selector bottom fixed
随机推荐
idea设置识别.sql文件类型以及其他文件类型
【SemiDrive源码分析】【MailBox核间通信】47 - 分析RPMSG_IPCC_RPC 方式 单次传输的极限大小 及 极限带宽测试
Performance testing with Loadrunner
Write golang simple C2 remote control based on gRPC
力扣:63. 不同路径 II
string类简介
word 公式编辑器 键入技巧 | 写数学作业必备速查表
Mini program + e-commerce, fun new retail
As soon as flink cdc is started, the CPU of the source Oracle server soars to more than 80%. What is the reason?
2022 software test interview questions The latest ByteDance 50 real interview questions, 15k have been won after brushing, with explanation + Q&A
Typora 使用保姆级教程 | 看这一篇就够了 | 历史版本已被禁用
2023年PMP考试会用新版教材吗?回复来了!
2022年PMP考试延迟了,该喜该忧?
DataTable使用Linq进行分组汇总,将Linq结果集转化为DataTable
Landing, the IFC, GFC, FFC concept, layout rules, forming method, use is analysed
使用Patroni回调脚本绑定VIP的坑
【JS】js给对象动态添加、设置、删除属性名和属性值
去重的几种方式
Dynamic programming of the division of numbers
3000 words, is take you understand machine learning!