springboot+mybatis-plus分页和条件查询
mybatis-plus分页查询拥有内置的page方法,前端页面向后台传入page和limit,后台调用page()方法可以得到分页结果。
分页
在Controller中添加分页方法
@ApiOperation(value = "分页讲师列表")
@GetMapping("{page}/{limit}")
public R pageList(
@ApiParam(name = "page", value = "当前页码", required = true)
@PathVariable Long page,
@ApiParam(name = "limit", value = "每页记录数", required = true)
@PathVariable Long limit){
Page<Teacher> pageParam = new Page<>(page, limit);
teacherService.page(pageParam, null);
List<Teacher> records = pageParam.getRecords();
long total = pageParam.getTotal();
return R.ok().data("total", total).data("rows", records);
}