1.简介
MyBatis Plus
自带分页插件,只要简单的配置即可实现分页功能
2.入门使用
2.1.创建配置类
此时可以删除主类中的
@MapperScan
扫描注解
@Component
public class MpInterceptor {
/**
* 分页拦截器,,存入Spring容器
* 拦截生成的sql语句,注入limit分页参数
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}
2.2.测试selectPage分页
@Resource
private UserMapper userMapper;
@Test
public void pageTest(){
Page<User> userPage = new Page<>(1,3);
userMapper.selectPage(userPage,null);
System.out.println("列表:");
List<User> list = userPage.getRecords();
list.forEach(System.out::println);
System.out.println("总数:"+userPage.getTotal());
System.out.println("当前页码 = " + userPage.getCurrent());
System.out.println("总页码 = " + userPage.getPages());
System.out.println("页码数量 = " + userPage.getSize());
System.out.println("总数量 = " + userPage.getTotal());
System.out.println("是否有下一页 = " + userPage.hasNext());
System.out.println("是否有上一页 = " + userPage.hasPrevious());
}