Mybatis的分页需要使用到工具PageHelper,PageHelper是GitHub开源的工具。
1,先导入相关依赖,pom.xml
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.10</version>
</dependency>
2,把工具PageHelper以插件的形式导入Mybatis.xml配置文件中
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
3,在查询方法中配置分页的参数
public void test(){
//查询前设置
PageHelper.startPage(1,3);//1是页码,3是每页显示条数
//分页支持排序
PageHelper.orderBy(“排序参数,顺序/倒序”);
//查询后封装
PageInfo<返回参数的类型> pageInfo = new PageInfo(查询返回集合);
}