1.

在maven中引入pagehelper相关依赖包:

<dependency>

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

    <artifactId>pagehelper</artifactId>

    <version>5.1.2</version>

</dependency>


MyBatis___:关于MyBatis的分页PageHelper插件使用

2.

在mybatis-config.xml注册分页插件

<plugins>

    <!-- com.github.pagehelper为PageHelper类所在包名 -->

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

</plugin>

</plugins>

MyBatis___:关于MyBatis的分页PageHelper插件使用

3.

在查询之前只需要调用传入的页面,以及每页的大小:

PageHelper.startPage(pn, 5);

MyBatis___:关于MyBatis的分页PageHelper插件使用
4.

startPage后面紧跟的这个查询就是一个分页的查询

List<Employee> employees =   this.employeeService.getAll();

MyBatis___:关于MyBatis的分页PageHelper插件使用
5.

使用怕个info包装查询后的结果:

PageInfo<Employee> pageInfo = new PageInfo<Employee>(employees);

MyBatis___:关于MyBatis的分页PageHelper插件使用
6.

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

MyBatis___:关于MyBatis的分页PageHelper插件使用

相关文章:

  • 2022-02-06
  • 2022-12-23
  • 2021-08-12
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
  • 2021-11-07
  • 2021-08-10
  • 2021-10-19
相关资源
相似解决方案