学习笔记——Mybatis分页插件

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

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实现后续分页效果

 

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6