1、 查询热门课程和讲师(8门课程,4名老师)
在service_edu模块添加IndexController。
@Api(description="前台首页展示")
@RestController
@RequestMapping("/eduservice/index")
@CrossOrigin
public class IndexController {
@Autowired
private EduCourseService courseService;
@Autowired
private EduTeacherService teacherService;
@ApiOperation(value = "首页展示8条课程信息,4位讲师")
@GetMapping
public R getIndexData(){
//1查询8条课程记录
//SELECT * FROM edu_course ec ORDER BY id DESC LIMIT 8;
QueryWrapper wrapperCourse = new QueryWrapper();
//1.1根据id进行降序排
wrapperCourse.orderByDesc("id");
//1.2查询8条记录
wrapperCourse.last("limit 8");
List eduCourseList = courseService.list(wrapperCourse);
//2查询4位讲师
QueryWrapper wrapperTeacher = new QueryWrapper();
wrapperTeacher.orderByDesc("id");
wrapperTeacher.last("limit 4");
List eduTeacherList = teacherService.list(wrapperTeacher);
return R.ok().data("hotCourse",eduCourseList).data("teacher",eduTeacherList);
}
}