MyBatis如何使用PageHelper插件实现分页查询

 时间:2024-10-14 06:25:06

1、在maven中引入pagehelper相关依赖包:<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.2</version> </dependency>

MyBatis如何使用PageHelper插件实现分页查询

2、在mybatis-config.xml注册分页插件<plugins> <!-- com.github.pagehelper为PageHelp髫潋啜缅er类所在包名 --> <plugin interceptor="com.github.pagehelper.PageInterceptor"> </plugin> </plugins>

MyBatis如何使用PageHelper插件实现分页查询

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

MyBatis如何使用PageHelper插件实现分页查询

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

MyBatis如何使用PageHelper插件实现分页查询

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

MyBatis如何使用PageHelper插件实现分页查询

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

MyBatis如何使用PageHelper插件实现分页查询
  • 万能数据库客户端dbvisualizer安装使用【一】
  • IntelliJ IDEA 怎么创建Scala项目
  • 教你Excel数据通过plsql导入到Oracle?
  • Aix,Linux怎样替换^M
  • Eclipse安装SpringBoot插件—zip包离线安装方式
  • 热门搜索
    蛇莓的功效与作用 秋葵的功效与作用禁忌 什么食物降火 弱水三千只取一瓢什么意思 甘草作用 热玛吉的功效作用及副作用 标题的作用 化学选修四知识点总结 什么的鞭炮声 两会什么时候召开