1、首先在配置类中配置插件
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
2、使用分页查询功能
int current=2;
int size=4;
Page<User> userPage = new Page<>(current, size);
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.eq("status","1");
Page<User> pageList = userMapper.selectPage(userPage, wrapper);
List<User> records = pageList.getRecords();