image.png

一、讲师列表

02 讲师分页列表功能.png

1、TeacherService

接口

  1. public Map<String, Object> pageListWeb(Page<Teacher> pageParam);

实现

  1. @Override
  2. public Map<String, Object> pageListWeb(Page<Teacher> pageParam) {
  3. QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
  4. queryWrapper.orderByAsc("sort");
  5. baseMapper.selectPage(pageParam, queryWrapper);
  6. List<Teacher> records = pageParam.getRecords();
  7. long current = pageParam.getCurrent();
  8. long pages = pageParam.getPages();
  9. long size = pageParam.getSize();
  10. long total = pageParam.getTotal();
  11. boolean hasNext = pageParam.hasNext();
  12. boolean hasPrevious = pageParam.hasPrevious();
  13. Map<String, Object> map = new HashMap<String, Object>();
  14. map.put("items", records);
  15. map.put("current", current);
  16. map.put("pages", pages);
  17. map.put("size", size);
  18. map.put("total", total);
  19. map.put("hasNext", hasNext);
  20. map.put("hasPrevious", hasPrevious);
  21. return map;
  22. }

2、TeacherController

  1. @ApiOperation(value = "分页讲师列表")
  2. @GetMapping(value = "{page}/{limit}")
  3. public R pageList(
  4. @ApiParam(name = "page", value = "当前页码", required = true)
  5. @PathVariable Long page,
  6. @ApiParam(name = "limit", value = "每页记录数", required = true)
  7. @PathVariable Long limit){
  8. Page<Teacher> pageParam = new Page<Teacher>(page, limit);
  9. Map<String, Object> map = teacherService.pageListWeb(pageParam);
  10. return R.ok().data(map);
  11. }

二、讲师详情

03 讲师详情功能.png

1、CourseService

根据讲师id查询讲师所讲课程列表
接口

  1. List<Course> selectByTeacherId(String teacherId);

实现

  1. /**
  2. * 根据讲师id查询当前讲师的课程列表
  3. * @param teacherId
  4. * @return
  5. */
  6. @Override
  7. public List<Course> selectByTeacherId(String teacherId) {
  8. QueryWrapper<Course> queryWrapper = new QueryWrapper<Course>();
  9. queryWrapper.eq("teacher_id", teacherId);
  10. //按照最后更新时间倒序排列
  11. queryWrapper.orderByDesc("gmt_modified");
  12. List<Course> courses = baseMapper.selectList(queryWrapper);
  13. return courses;
  14. }

2、TeacherController

  1. @Autowired
  2. private CourseService courseService;

修改getById方法:

  1. @ApiOperation(value = "根据ID查询讲师")
  2. @GetMapping(value = "{id}")
  3. public R getById(
  4. @ApiParam(name = "id", value = "讲师ID", required = true)
  5. @PathVariable String id){
  6. //查询讲师信息
  7. Teacher teacher = teacherService.getById(id);
  8. //根据讲师id查询这个讲师的课程列表
  9. List<Course> courseList = courseService.selectByTeacherId(id);
  10. return R.ok().data("teacher", teacher).data("courseList", courseList);
  11. }