学习笔记——Mybatis分页插件

2023-01-13

一、Mybatis分页插件

1、使用分页插件的原因

(1)提高用户体验度

(2)降低服务器端压力

2、设计Page类

设计原则:当前页面/总页数。Eg:25/40

(1)pageNum:当前页面

(2)pages:总页数(总页数=总数据数量/每页显示数据数量)

(3)total:总数据数量

(4)pageSize:每页显示数据数量

(5)List<T>:当前页显示数据集合

3、PageHelper

(1)概述:PageHelper是Mybatis中非常方便的第三方分页插件。

(2)官方文档:

https://github.com/pagehelper/Mybatis-PageHelper/blob/master/README_zh.md

(3)PageHelper使用步骤

①导入PageHelper的相关jar包

<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>5.0.0</version>
</dependency>

②在mybatis-config.xml中配置分页插件

<plugins>
       <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>

③查询之前,使用PageHelper开启分页

PageHelper.startPage(1,3);

④查询之后,可以使用更强大的PageInfo中,使用PageInfo实现后续分页效果

 

posted @   努力是一种常态  阅读(795)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示