Pagehelper分页使用
使用方法
1. 引入分页插件
引入分页插件有下面2种方式,推荐使用 Maven 方式。
1). 引入 Jar 包
你可以从下面的地址中下载最新版本的 jar 包
-
https://oss.sonatype.org/content/repositories/releases/com/github/pagehelper/pagehelper/
-
http://repo1.maven.org/maven2/com/github/pagehelper/pagehelper/
由于使用了sql 解析工具,你还需要下载 jsqlparser.jar(需要和PageHelper 依赖的版本一致) :
2). 使用 Maven
在 pom.xml 中添加如下依赖:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>最新版本</version>
</dependency>
最新版本号可以从首页查看。
2. 配置拦截器插件
特别注意,新版拦截器是 com.github.pagehelper.PageInterceptor
。 com.github.pagehelper.PageHelper
现在是一个特殊的 dialect
实现类,是分页插件的默认实现类,提供了和以前相同的用法。
1. 在 MyBatis 配置 xml 中配置拦截器插件
<!--
plugins在配置文件中的位置必须符合要求,否则会报错,顺序如下:
properties?, settings?,
typeAliases?, typeHandlers?,
objectFactory?,objectWrapperFactory?,
plugins?,
environments?, databaseIdProvider?, mappers?
-->
<plugins>
<!-- com.github.pagehelper为PageHelper类所在包名 -->
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<!-- 使用下面的方式配置参数,后面会有所有的参数介绍 -->
<property name="param1" value="value1"/>
</plugin>
</plugins>
参考地址:https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/HowToUse.md
学习本是一个不断抄袭、模仿、练习、创新的过程。
虽然,园中已有本人无法超越的同主题博文,为什么还是要写。
对于自己,博文只是总结。在总结的过程发现问题,解决问题。
对于他人,在此过程如果还能附带帮助他人,那就再好不过了。
由于博主能力有限,文中可能存在描述不正确,欢迎指正、补充!
感谢您的阅读。如果文章对您有用,那么请轻轻点个赞,以资鼓励。