在线教育项目-day13【讲师相关接口】

一、讲师相关方法

1.controller

@RestController
@RequestMapping("eduservice/teacherfront")
@CrossOrigin
public class TeacherFrontController {
    @Autowired
    EduTeacherService teacherService;

    @Autowired
    EduCourseService courseService;

    //分页查询讲师方法
    @GetMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher> pageTeacher=new Page<>(page,limit);
        Map<String,Object> map=teacherService.getTeacherList(pageTeacher);
        return R.OK().data(map);
    }
    //讲师详情
    @GetMapping(value = "{id}")
    public R getById(@PathVariable String id){
        //查询讲师信息
        EduTeacher teacher = teacherService.getById(id);
        //根据讲师id查询这个讲师的课程列表
        List<EduCourse> courseList = courseService.selectByTeacherId(id);

        return R.OK().data("teacher", teacher).data("courseList", courseList);
    }
}

2.sevice

List<EduCourse> selectByTeacherId(String id);
Map<String, Object> getTeacherList(Page<EduTeacher> pageTeacher);

3.serviceImpl

public Map<String, Object> getTeacherList(Page<EduTeacher> pageTeacher) {
        QueryWrapper<EduTeacher> wrapper=new QueryWrapper<>();
        wrapper.orderByDesc("id");
        baseMapper.selectPage(pageTeacher,wrapper);
        List<EduTeacher> records=pageTeacher.getRecords();
        long current=pageTeacher.getCurrent();
        long pages=pageTeacher.getPages();
        long size=pageTeacher.getSize();
        long total=pageTeacher.getTotal();
        boolean hasNext=pageTeacher.hasNext();
        boolean hasPrevious=pageTeacher.hasPrevious();
        //把分页数据获取出来
        Map<String,Object> map=new HashedMap<>();
        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;
    }
 @Override
    public List<EduCourse> selectByTeacherId(String teacherId) {

        QueryWrapper<EduCourse> queryWrapper = new QueryWrapper<EduCourse>();

        queryWrapper.eq("teacher_id", teacherId);
        //按照最后更新时间倒序排列
        queryWrapper.orderByDesc("gmt_modified");

        List<EduCourse> courses = baseMapper.selectList(queryWrapper);

        return courses;
    }

二、swagger测试

1.讲师分页查询接口

在线教育项目-day13【讲师相关接口】

 

 在线教育项目-day13【讲师相关接口】

 

 2.讲师详情

我们先更改一下数据库,比如我们查大司马,然后在课程的表中给他一门课程

在线教育项目-day13【讲师相关接口】

 

 在线教育项目-day13【讲师相关接口】

 

 ok查询成功

在线教育项目-day13【讲师相关接口】

 

上一篇:POI-Excel读


下一篇:day13【Collection、泛型】