首先先配置配置文件
@Configuration public class MybatisPlusConfig { @Bean public PaginationInterceptor paginationInterceptor() { return new PaginationInterceptor(); } }
2.进行分页查询
@Test public void selectPage() { QueryWrapper<User> wrapper = new QueryWrapper<>(); wrapper.ge("age",26); Page<User> page = new Page<>(1, 2); IPage<User> userIPage = userMapper.selectPage(page, wrapper); System.out.println("总条数"+userIPage.getTotal()); System.out.println("总页数"+userIPage.getPages()); }
@Test public void selectPage() { QueryWrapper<User> wrapper = new QueryWrapper<>(); wrapper.ge("age",26); Page<User> page = new Page<>(1, 2); IPage<Map<String,Object>> userIPage = userMapper.selectMapsPage(page, wrapper); System.out.println("总条数"+userIPage.getTotal()); System.out.println("总页数"+userIPage.getPages()); }