以下内容参考自下面视频:
https://www.bilibili.com/video/BV1y7411y7am
1.分页查询
1.1 配置分页插件
在EduConfig类中配置
/**
* 分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor(){
return new PaginationInterceptor();
}
1.2 在Controller中调用
/**
* 分页查询
*/
@GetMapping("pageTeacher/{current}/{limit}")
public R pageListTeacher(@PathVariable long current,@PathVariable long limit){
Page<EduTeacher> pageTeacher = new Page<>(current, limit);
teacherService.page(pageTeacher, null);
long total = pageTeacher.getTotal();
List<EduTeacher> records = pageTeacher.getRecords();
return R.ok().data("total",total).data("records",records);
}
2.条件、分页组合查询
2.1 创建条件查询实体类
@Data
public class TeacherQuery {
@ApiModelProperty(value = "教师名称,模糊查询")
private String name;
@ApiModelProperty(value = "头衔 1高级讲师 2首席讲师")
private Integer level;
@ApiModelProperty(value = "查询开始时间", example = "2019-01-01 10:10:10")
private String begin;//注意,这里使用的是String类型,前端传过来的数据无需进行类型转换
@ApiModelProperty(value = "查询结束时间", example = "2019-12-01 10:10:10")
private String end;
}
2.2 在Controller中调用
@RequestBody(required = false) 传递的参数以json形式传递,可以没有
@PostMapping 使用Post才能接收到json形式的参数,get不行
/**
* 条件、分页组合查询
*/
@PostMapping("pageTeacherCondition/{current}/{limit}")
public R pageTeacherCondition(@PathVariable long current, @PathVariable long limit,
@RequestBody(required = false)TeacherQuery teacherQuery){
//创建page对象
Page<EduTeacher> pageTeacher = new Page<>(current, limit);
//创建wrapper对象
QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();
//判断teacherQuery对象中的属性是否为空,不为空的话,添加到wrapper中
String name = teacherQuery.getName();
Integer level = teacherQuery.getLevel();
String begin = teacherQuery.getBegin();
String end = teacherQuery.getEnd();
if (!StringUtils.isEmpty(name)){
wrapper.like("name",name);
}
if (!StringUtils.isEmpty(level)){
wrapper.eq("lever",level);
}
if (!StringUtils.isEmpty(begin)){
wrapper.ge("gmt_create",begin);
}
if (!StringUtils.isEmpty(end)){
wrapper.ge("gmt_create",end);
}
//查询
teacherService.page(pageTeacher, wrapper);
long total = pageTeacher.getTotal();
List<EduTeacher> records = pageTeacher.getRecords();
return R.ok().data("total",total).data("records",records);
}
3.添加讲师
3.1 添加注解
在实体类的属性上添加字自动填充注解
@ApiModelProperty(value = "创建时间")
@