select ec.id,ec.title,ec.price,ec.lesson_num as lessonNum,ec.cover, et.name as teacherName, es1.title as subjectLevelOne, es2.title as subjectLevelTwo from edu_course ec leftouterjoin edu_course_description ecd on ec.id = ecd.id leftouterjoin edu_teacher et on ec.teacher_id = et.id leftouterjoin edu_subject es1 on ec.subject_parent_id = es1.id leftouterjoin edu_subject es2 on ec.subject_id = es2.id where ec.id ='1670024852233478146'
public CoursePublishVo getPublishCourseInfo(String courseId); }
在映射文件中写sql语句
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mappernamespace="com.atguigu.eduservice.mapper.EduCourseMapper"> <!--sql语句:根据课程id查询课程确认信息--> <selectid="getPublishCourseInfo"resultType="com.atguigu.eduservice.entity.vo.CoursePublishVo"> SELECT ec.id,ec.title,ec.price,ec.lesson_num AS lessonNum,ec.cover, et.name AS teacherName, es1.title AS subjectLevelOne, es2.title AS subjectLevelTwo FROM edu_course ec LEFT OUTER JOIN edu_course_description ecd ON ec.id=ecd.id LEFT OUTER JOIN edu_teacher et ON ec.teacher_id=et.id LEFT OUTER JOIN edu_subject es1 ON ec.subject_parent_id=es1.id LEFT OUTER JOIN edu_subject es2 ON ec.subject_id=es2.id WHERE ec.id=#{courseId} </select> </mapper>
在controller层写接口
1 2 3 4 5 6
//根据课程id查询课程确认信息 @GetMapping("getPublishCourseInfo/{id}") public R getPublishCourseInfo(@PathVariable String id) { CoursePublishVocoursePublishVo= courseService.publishCourseInfo(id); return R.ok().data("publishCourse",coursePublishVo); }