1、通过编写sql语句,查询课程信息
java
SELECT * FROM edu_course ec
LEFT JOIN edu_course_description ecd ON ec.id = ecd.id
LEFT JOIN edu_teacher et ON ec.teacher_id = et.id
WHERE ec.id =18;
2、编写接口信息
(1)创建展示vo类 在com/atguigu/eduservice/entity/vo中添加CourseWebVo类。
java
@Data
public class CourseWebVo {
private String id;
@ApiModelProperty(value = "课程标题")
private String title;
@ApiModelProperty(value = "课程销售价格,设置为0则可免费观看")
private BigDecimal price;
@ApiModelProperty(value = "总课时")
private Integer lessonNum;
@ApiModelProperty(value = "课程封面图片路径")
private String cover;
@ApiModelProperty(value = "销售数量")
private Long buyCount;
@ApiModelProperty(value = "浏览数量")
private Long viewCount;
@ApiModelProperty(value = "课程简介")
private String description;
@ApiModelProperty(value = "讲师ID")
private String teacherId;
@ApiModelProperty(value = "讲师姓名")
private String teacherName;
@ApiModelProperty(value = "讲师资历,一句话说明讲师")
private String intro;
@ApiModelProperty(value = "讲师头像")
private String avatar;
@ApiModelProperty(value = "课程类别ID")
private String subjectLevelOneId;
@ApiModelProperty(value = "类别名称")
private String subjectLevelOne;
@ApiModelProperty(value = "课程类别ID")
private String subjectLevelTwoId;
@ApiModelProperty(value = "类别名称")
private String subjectLevelTwo;
}
(2)实现Controller
在com/atguigu/eduservice/api目录下的CourseApiController添加根据id查询课程详情方法。
java
@ApiOperation(value = "根据id查询课程详情")
@GetMapping("getCourseInfo/{id}")
public R getCourseInfo(@PathVariable String id){
//1查询课程详情信息
CourseWebVo courseWebVo = courseService.getCourseWebVo(id);
//2查询课程相关大纲数据
List<ChapterVo> chapterVideoList = chapterService.getChapterVideoById(id);
return R.ok().data("courseWebVo",courseWebVo).data("chapterVideoList",chapterVideoList);
}
(3)在EduCourseService中添加接口
java
CourseWebVo getCourseWebVo(String id);
(4)在EduCourseServiceImpl中实现接口的方法
java
//根据id查询课程详情(前台)
@Override
public CourseWebVo getCourseWebVo(String id) {
CourseWebVo courseWebVo = baseMapper.getFrontCourseInfo(id);
return courseWebVo;
}
(5)编写mapper接口 在com/atguigu/eduservice/mapper目录下EduCourseMapper中编写mapper接口。
java
CourseWebVo getFrontCourseInfo(String id);
(6)实现mapper接口方法 在com/atguigu/eduservice/mapper/xml目录下实现mapper接口方法。
java
<select id="getFrontCourseInfo" resultType="com.atguigu.eduservice.entity.vo.CourseWebVo">
SELECT ec.id,ec.title,ec.price,ec.cover,ec.lesson_num AS lessonNum,
ec.buy_count AS buyCount,ec.view_count AS viewCount,
ecd.description,et.id AS teacherId,et.name AS teacherName,
et.intro,et.avatar
FROM edu_course ec
LEFT JOIN edu_course_description ecd ON ec.id = ecd.id
LEFT JOIN edu_teacher et ON ec.teacher_id = et.id
WHERE ec.id =#{id}
</select>