MyBatis如何使用PageHelper插件实现分页查询
1、在maven中引入pagehelper相关依赖包:
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>

2、在mybatis-config.xml注册分仗屈王页插件
<plugins>
<!-- com.github.pagehelper为PageHelper类所在包名 -->
<plugin interceptor="com.github.pagehelper.PageInterceptor">
</plugin>
</plugins>

3、在查询之前只需要调用传入的页面,以及每页的大小:
PageHelper.startPage(pn, 5);

4、startPage后面紧跟追之的这个查询就是一个分页的查询
List<Employee> employees = 杰粒 this.employeeService.getAll();

5、使用怕个info包装查询后的结果:
PageInfo<Employee> pageInfo = new PageInfo<Employee>(employees);

6、PageInfo封装了详细的分页信息,包括有我们查询出来的数据

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:145
阅读量:172
阅读量:196
阅读量:154
阅读量:134