课程管理之多条件查询
1、分页查询的步骤,只是有添加条件
2、创建一个对象用于封装前端传过来的模糊查询的数据
public class CourseQuery {
@ApiModelProperty(value = "课程名称")
private String name;
@ApiModelProperty(value = "课程状态")
private String status;
}
3、写controller
//多条件的分页显示
@GetMapping("/pageCourseCondition/{current}/{limit}")
public R pageCourseCondition(@PathVariable long current,
@PathVariable long limit,
@RequestBody(required = false) CourseQuery courseQuery) {
Page<EduCourse> eduCoursePage = new Page<>(current,limit);
QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
String name = courseQuery.getName();
String status = courseQuery.getStatus();
if(!StringUtils.isEmpty(name)){
wrapper.like("name",name);
}
if(!StringUtils.isEmpty(status)){
wrapper.eq("status",status);
}
eduCourseService.page(eduCoursePage,wrapper);
long total = eduCoursePage.getTotal();
List<EduCourse> records = eduCoursePage.getRecords();
return R.ok().data("total",total).data("records",records);
}