配置分页插件
在配置类中注册分页插件
// 最新版
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2));
return interceptor;
}
直接调用
//分页查询
@Test
void getUserByPage(){
//2:代表当前页
//4:页面记录数量
Page<User> page = new Page<>(2,4);
userService.page(page);
page.getRecords().forEach(System.out::println); //通过page对象可以获取更多信息
}