首页显示热门课程和名师(接口)
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<EduCourse> wrapperCourse = new QueryWrapper<>();
//1.1根据id进行降序排
wrapperCourse.orderByDesc("id");
//1.2查询8条记录
wrapperCourse.last("limit 8");
List<EduCourse> eduCourseList = courseService.list(wrapperCourse);
//2查询4位讲师
QueryWrapper<EduTeacher> wrapperTeacher = new QueryWrapper<>();
wrapperTeacher.orderByDesc("id");
wrapperTeacher.last("limit 4");
List<EduTeacher> eduTeacherList = teacherService.list(wrapperTeacher);
return R.ok().data("hotCourse",eduCourseList).data("teacher",eduTeacherList);
}
}
2、测试
转载自:https://juejin.cn/post/7283748394601250856