当前位置:网站首页>12. Paging plugin
12. Paging plugin
2022-08-04 05:32:00 【ape white】
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);
// Before open the paging query function
Page<Object> pages = PageHelper.startPage(1, 4);
List<Emp> emps = mapper.selectByExample(null);
// After the query functionality can get all the data of paging related
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]}
}
边栏推荐
- C Expert Programming Chapter 5 Thinking about Chaining 5.6 Take it easy --- see who's talking: take the Turning quiz
- Get the selected content of the radio box
- day13--postman接口测试
- 有趣的 Kotlin 0x0E:DeepRecursiveFunction
- C Expert Programming Chapter 4 The Shocking Fact: Arrays and Pointers Are Not the Same 4.3 What is a Declaration and What is a Definition
- Interesting Kotlin 0x0E: DeepRecursiveFunction
- 字节最爱问的智力题,你会几道?
- Dynamic programming of the division of numbers
- The difference between px, em, and rem
- Turn: Management is the love of possibility, and managers must have the courage to break into the unknown
猜你喜欢

代码重构:面向单元测试

Shocked, 99.9% of the students didn't really understand the immutability of strings
![[Cocos 3.5.2]开启模型合批](/img/d9/9e8f71c9a26c8052b11291fe3ba7ac.png)
[Cocos 3.5.2]开启模型合批

What is the salary of a software testing student?

MySQL数据库(基础)
![[One step in place] Jenkins installation, deployment, startup (complete tutorial)](/img/f2/15fb546eb864d7ff40b5507d5c7aa5.png)
[One step in place] Jenkins installation, deployment, startup (complete tutorial)

7.16 Day22---MYSQL(Dao模式封装JDBC)

Towards Real-Time Multi-Object Tracking (JDE)

4.3 基于注解的声明式事务和基于XML的声明式事务

px、em、rem的区别
随机推荐
你以为border-radius只是圆角吗?【各种角度】
12、分页插件
DataTable uses Linq for grouping and summarization, and converts the Linq result set into DataTable
7.16 Day22---MYSQL(Dao模式封装JDBC)
C1认证之web基础知识及习题——我的学习笔记
4.3 基于注解的声明式事务和基于XML的声明式事务
canal实现mysql数据同步
TSF微服务治理实战系列(一)——治理蓝图
[Cocos] cc.sys.browserType可能的属性
处理List<Map<String, String>>类型
Cannot read properties of null (reading ‘insertBefore‘)
代码重构:面向单元测试
redis中常见的面试题
Chapter 5 C programming expert thinking 5.4 alert Interpositioning of links
力扣:70. 爬楼梯
4.2 声明式事务概念
string类简介
文献管理工具 | Zotero
The difference between px, em, and rem
9. Dynamic SQL