首先先配置配置文件
代码语言:javascript复制@Configuration
public class MybatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}
2.进行分页查询
代码语言:javascript复制 @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());
}
代码语言:javascript复制 @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());
}