码迷,mamicode.com
首页 > 其他好文 > 详细

Mybatis的分页插件PageHelper分页失效的原因

时间:2019-02-13 22:38:20      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:依赖   pre   start   inter   tis   个人博客   type   导入   lis   

引用博客:个人博客地址:https://alexaccele.github.io/

PageHelper是Mybatis的一个很好的分页插件,但要使用它的分页功能需要注意一下几点

1.导入相关包,例如maven导入依赖

1 <dependency>
2     <groupId>com.github.pagehelper</groupId>
3     <artifactId>pagehelper</artifactId>
4     <version>5.1.4</version>
5 </dependency>

2.在mybatis-config.xml中添加插件

1 <plugins>
2     <plugin interceptor="com.github.pagehelper.PageInterceptor">
3         <!--分页参数合理化  -->
4         <property name="reasonable" value="true"/>
5     </plugin>
6 </plugins>

3.在Controller的方法中

PageHelper.startPage(1,5);//从第一页开始,每页5条记录

以上代码后面需紧跟查询语句

1 List<Test> tests = testService.getAllTestsByTypeId(testTypeid);
2 PageInfo pageInfo = new PageInfo(tests,5);

当一个方法中有多个查询语句时,只有紧跟在PageHelper.starPage()方法后的查询结果才会分页。

缺少以上三步都会导致分页失效

Mybatis的分页插件PageHelper分页失效的原因

标签:依赖   pre   start   inter   tis   个人博客   type   导入   lis   

原文地址:https://www.cnblogs.com/116970u/p/10371964.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!