实现课程详情接口

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>
相关推荐
Nicole Potter7 分钟前
请说明C#中的List是如何扩容的?
开发语言·面试·c#
北_鱼12 分钟前
支持向量机(SVM):算法讲解与原理推导
算法·机器学习·支持向量机
sjsjsbbsbsn22 分钟前
Spring Boot定时任务原理
java·spring boot·后端
计算机毕设指导61 小时前
基于Springboot学生宿舍水电信息管理系统【附源码】
java·spring boot·后端·mysql·spring·tomcat·maven
计算机-秋大田1 小时前
基于Spring Boot的兴顺物流管理系统设计与实现(LW+源码+讲解)
java·vue.js·spring boot·后端·spring·课程设计
MZWeiei2 小时前
PTA:运用顺序表实现多项式相加
算法
GISer_Jing2 小时前
Javascript排序算法(冒泡排序、快速排序、选择排序、堆排序、插入排序、希尔排序)详解
javascript·算法·排序算法
cookies_s_s2 小时前
Linux--进程(进程虚拟地址空间、页表、进程控制、实现简易shell)
linux·运维·服务器·数据结构·c++·算法·哈希算法
拉不动的猪3 小时前
刷刷题16
前端·javascript·面试
不想编程小谭3 小时前
力扣LeetCode: 2506 统计相似字符串对的数目
c++·算法·leetcode