讲师分页查询
1、添加插件
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
2、实现方法
@ApiOperation(value = "分页查询讲师列表")
@GetMapping("getTeacherPage/{current}/{limit}")
public R getTeacherPage(@PathVariable Long current,
@PathVariable Long limit){
Page<EduTeacher> page = new Page<>(current,limit);
teacherService.page(page,null);
List<EduTeacher> records = page.getRecords();
long total = page.getTotal();
return R.ok().data("list",records).data("total",total);
}
3、测试
讲师条件查询带分页
1、需求分析
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3887fa6ee14075a9f26a06666a87cc6d.png)
2、实现接口
(1)创建VO对象
@Data
public class TeacherQuery implements Serializable {
@ApiModelProperty(value = "教师名称,模糊查询")
private String name;
@ApiModelProperty(value = "头衔 1高级讲师 2首席讲师")
private Integer level;
@ApiModelProperty(value = "查询开始时间", example = "2019-01-01 10:10:10")
private String begin;
@ApiModelProperty(value = "查询结束时间", example = "2019-12-01 10:10:10")
private String end;
}
(2)实现方法
@ApiOperation(value = "带条件分页查询讲师列表")
@PostMapping("getTeacherPageVo/{current}/{limit}")
public R getTeacherPageVo(@PathVariable Long current,
@PathVariable Long limit,
@RequestBody TeacherQuery teacherQuery){
String name = teacherQuery.getName();
Integer level = teacherQuery.getLevel();
String begin = teacherQuery.getBegin();
String end = teacherQuery.getEnd();
QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();
if(!StringUtils.isEmpty(name)){
wrapper.like("name",name);
}
if(!StringUtils.isEmpty(level)){
wrapper.eq("level",level);
}
if(!StringUtils.isEmpty(begin)){
wrapper.ge("gmt_create",begin);
}
if(!StringUtils.isEmpty(end)){
wrapper.le("gmt_create",end);
}
Page<EduTeacher> page = new Page<>(current,limit);
teacherService.page(page,wrapper);
List<EduTeacher> records = page.getRecords();
long total = page.getTotal();
return R.ok().data("list",records).data("total",total);
}