一、讲师列表
1、TeacherService
接口
public Map<String, Object> pageListWeb(Page<Teacher> pageParam);
实现
@Override
public Map<String, Object> pageListWeb(Page<Teacher> pageParam) {
QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
queryWrapper.orderByAsc("sort");
baseMapper.selectPage(pageParam, queryWrapper);
List<Teacher> records = pageParam.getRecords();
long current = pageParam.getCurrent();
long pages = pageParam.getPages();
long size = pageParam.getSize();
long total = pageParam.getTotal();
boolean hasNext = pageParam.hasNext();
boolean hasPrevious = pageParam.hasPrevious();
Map<String, Object> map = new HashMap<String, Object>();
map.put("items", records);
map.put("current", current);
map.put("pages", pages);
map.put("size", size);
map.put("total", total);
map.put("hasNext", hasNext);
map.put("hasPrevious", hasPrevious);
return map;
}
2、TeacherController
@ApiOperation(value = "分页讲师列表")
@GetMapping(value = "{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<Teacher>(page, limit);
Map<String, Object> map = teacherService.pageListWeb(pageParam);
return R.ok().data(map);
}
二、讲师详情
1、CourseService
根据讲师id查询讲师所讲课程列表
接口
List<Course> selectByTeacherId(String teacherId);
实现
/**
* 根据讲师id查询当前讲师的课程列表
* @param teacherId
* @return
*/
@Override
public List<Course> selectByTeacherId(String teacherId) {
QueryWrapper<Course> queryWrapper = new QueryWrapper<Course>();
queryWrapper.eq("teacher_id", teacherId);
//按照最后更新时间倒序排列
queryWrapper.orderByDesc("gmt_modified");
List<Course> courses = baseMapper.selectList(queryWrapper);
return courses;
}
2、TeacherController
@Autowired
private CourseService courseService;
修改getById方法:
@ApiOperation(value = "根据ID查询讲师")
@GetMapping(value = "{id}")
public R getById(
@ApiParam(name = "id", value = "讲师ID", required = true)
@PathVariable String id){
//查询讲师信息
Teacher teacher = teacherService.getById(id);
//根据讲师id查询这个讲师的课程列表
List<Course> courseList = courseService.selectByTeacherId(id);
return R.ok().data("teacher", teacher).data("courseList", courseList);
}