Python 官方文档:入门教程 => 点击学习
方法: 使用selectPage()方法,第一个参数是传入分页方法(传入当前页和当前显示多少条数据),第二个参数是传入查询条件(如果查询全部的话,可以传null)。 前提: 表中的
使用selectPage()方法,
第一个参数是传入分页方法(传入当前页和当前显示多少条数据),
第二个参数是传入查询条件(如果查询全部的话,可以传null)。
前提:
表中的数据为:
//分页查询
Page<Employee> employees = employeeMapper.selectPage(new Page<>(3, 2), null);
System.out.println("数据为:"+employees.getRecords());
System.out.println("总数为:"+employees.getTotal()+",总页数为:"+employees.getPages());
System.out.println("当前页为:"+employees.getCurrent()+",每页限制:"+employees.getSize());
结果为:
展示了所有的数据,也没有总数,并没有分页的效果。
//分页查询
Page<Employee> employees = employeeMapper.selectPage(new Page<>(3, 2), null);
Integer count = employeeMapper.selectCount(null);
employees.setTotal(count);
System.out.println("数据为:"+employees.getRecords());
System.out.println("总数为:"+employees.getTotal()+",总页数为:"+employees.getPages());
System.out.println("当前页为:"+employees.getCurrent()+",每页限制:"+employees.getSize());
结果为:
虽然有了总数和总页数,但依然没有分页的效果。
//分页查询
Page<Employee> employees = employeeMapper.selectPage(new Page<>(3, 2), null);
System.out.println("数据为:"+employees.getRecords());
System.out.println("总数为:"+employees.getTotal()+",总页数为:"+employees.getPages());
System.out.println("当前页为:"+employees.getCurrent()+",每页限制:"+employees.getSize());
@Configuration
public class MyBatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor(){
PaginationInterceptor page = new PaginationInterceptor();
return page;
}
}
结果:
到此这篇关于MyBatis-Plus 分页查询的实现示例的文章就介绍到这了,更多相关MyBatis-Plus 分页查询内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: MyBatis-Plus 分页查询的实现示例
本文链接: https://www.lsjlt.com/news/141455.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0