添加分页插件
@Bean
public PaginationInterceptor paginationInterceptor(){
return new PaginationInterceptor();
}
编写讲师分页查询接口的方法
@GetMapping("packageTeacher/{current}/{limit}")
public R packageListTeacher(@PathVariable long current,
@PathVariable long limit){
//创建page对象
Page<EduTeacher> pageTeacher = new Page<>(current,limit);
try {
int i=12/0;
} catch (Exception e) {
//执行自定义异常处理
throw new GuliException(20001,"执行自定义异常处理");
}
//调用方法实现分页
//调用方法时底层封装,把分页所有数据封装到pageTeacher对象里面
teacherService.page(pageTeacher,null);
long total = pageTeacher.getTotal();
List<EduTeacher> records = pageTeacher.getRecords();
return R.ok().data("total",total).data("rows",records);
}