前言:使用mybatis整合时,最容易遇到的需求就是分页了,pagehelper 分页插件是一个非常实用的 MyBatis分页插件,可以快速的实现MyBatis分页功能,而且pagehelper有个优点就是分页和Mapper.xml完全解耦,并以插件的形式实现,有效的避免了直接写分页SQL语句来实现分页功能
分页插件原理:分页插件的基本原理是使用Mybatis提供的插件接口,实现自定义插件,在插件的拦截方法内拦截待执行的sql,然后重写sql,添加对应的物理分页语句和物理分页参数
举例:select * from student,拦截sql后重写为:select t.* from (select * from student)t limit 0,10
1.引入pagehelper依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.11</version>
</dependency>
2.配置拦截器
这个是配置在mybatis-config.xml文件中
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
<property name&#