PageInfo(github)
导入依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.4.2</version>
</dependency>
controller
@ApiOperation("分页查询后台菜单")
@RequestMapping(value = "/list/{parentId}", method = RequestMethod.GET)
@ResponseBody
public CommonResult<CommonPage<UmsMenu>> list(@PathVariable Long parentId,
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
List<UmsMenu> menuList = menuService.list(parentId, pageSize, pageNum);
PageInfo<UmsMenu> pageInfo = new PageInfo<>(menuList);
return CommonResult.success(pageInfo);
}
service
@Override
public List<UmsMenu> list(Long parentId, Integer pageSize, Integer pageNum) {
PageHelper.startPage(pageNum, pageSize);
UmsMenuExample example = new UmsMenuExample();
example.setOrderByClause("sort desc");
example.createCriteria().andParentIdEqualTo(parentId);
// 此处查询的结果集为第pageNum的数据
return menuMapper.selectByExample(example);
}
Page(MybatisPlus)
配置类
/**
* 配置MP的分页插件
*/
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return mybatisPlusInterceptor;
}
}
controller
@GetMapping("/list")
public Result<Page> pageDemo(int pageNum, int pageSize) {
// 构造分页构造器
Page pageInfo = new Page(pageNum, pageSize);
// 构造条件构造器
LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.orderByDesc(Employee::getUpdateTime);
// 执行查询(page是内部函数)
employeeService.page(pageInfo, queryWrapper);
return Result.success(pageInfo);
}
标签:pageNum,分页,pageSize,list,查询,parentId,new,public From: https://www.cnblogs.com/ReturnOfTheKing/p/17707003.html