MyBatis分页插件

---------------------siwuxie095

   

   

   

   

   

   

   

   

   

MyBatis 分页插件

   

   

1、MyBatis 的分页插件 PageHelper分页助手) 实现了通用的分页

查询,并支持任何复杂的单表、多表分页。目前,该插件支持 MySQL、

Oracle、SQL Server、DB2、PostgreSQL 等主流数据库的物理分页

   

   

   

2、分页插件 PageHelper 的 Github 链接:

   

https://github.com/pagehelper/Mybatis-PageHelper

   

   

   

3分页插件需要搭配 sql 解析工具使用,所以引入分页插件有两种方式

   

1引入 jar 包

   

1)PageHelper 的下载链接如下:

   

https://oss.sonatype.org/content/repositories/releases/com/github/pagehelper/pagehelper/

   

   

http://repo1.maven.org/maven2/com/github/pagehelper/pagehelper/

   

   

2)JSqlParser 的下载链接如下:

   

http://repo1.maven.org/maven2/com/github/jsqlparser/jsqlparser/0.9.5/

   

   

2使用 Maven

   

Maven 项目的核心配置文件 pom.xml 中添加如下依赖:

   

<dependency>

<groupId>com.github.pagehelper</groupId>

<artifactId>pagehelper</artifactId>

<version>最新版本</version>

</dependency>

   

<dependency>

<groupId>com.github.jsqlparser</groupId>

<artifactId>jsqlparser</artifactId>

<version>最新版本</version>

</dependency>

   

   

   

4、在 MyBatis 核心配置文件 mybatis-config.xml 中进行配置

   

1)如果 PageHelper 的 jar 包版本是 4.x,则为:

   

<plugins>

 

<!-- com.github.pagehelperPageHelper类所在包名 -->

<plugin interceptor="com.github.pagehelper.PageHelper">

 

<!-- 指定数据库的方言为mysql -->

<property name="dialect" value="mysql"/>

<!-- 该参数默认为false -->

<!-- 设置为true时,使用RowBounds分页会进行count查询 -->

<property name="rowBoundsWithCount" value="true"/>

 

</plugin>

 

</plugins>

   

   

   

2)如果 PageHelper 的 jar 包版本是 5.x,则为:

   

<plugins>

 

<!-- com.github.pagehelperPageInterceptor类所在包名 -->

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

 

<!-- 指定数据库的方言为mysql -->

<property name="helperDialect" value="mysql"/>

<!-- 该参数默认为false -->

<!-- 设置为true时,使用RowBounds分页会进行count查询 -->

<property name="rowBoundsWithCount" value="true"/>

 

</plugin>

 

</plugins>

   

   

   

注:截止目前(2018/01/29),PageHelper 的最新版本是 5.1.2

   

   

   

5、其它配置及使用方法,详见如下链接:

   

https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/HowToUse.md

   

   

   

   

   

   

   

   

   

   

【made by siwuxie095】

原文地址:https://www.cnblogs.com/siwuxie095/p/8376285.html