实现课程详情接口

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>
相关推荐
申阳13 分钟前
Day 12:09. 基于Nuxt开发博客项目-使用NuxtContent构建博客模块
前端·后端·程序员
得物技术15 分钟前
Golang HTTP请求超时与重试:构建高可靠网络请求|得物技术
java·后端·go
信码由缰29 分钟前
Java 缓存精要
后端
吃饺子不吃馅36 分钟前
面试过别人后,我对面试祛魅了
前端·面试·github
t1987512838 分钟前
基于盲源分离与贝叶斯非局部均值(BM3D)的图像降噪算法实现
算法·计算机视觉·均值算法
2501_9411118441 分钟前
分布式日志系统实现
开发语言·c++·算法
朝新_43 分钟前
Spring事务和事务传播机制
数据库·后端·sql·spring·javaee
uhakadotcom1 小时前
fastapi的最新版本,提供了哪些新api可供使用
前端·面试·github
222you1 小时前
SpringBoot对SpringMVC的整合
java·spring boot·后端
刘一说1 小时前
深入理解 Spring Boot 高级特性:条件化 Bean 注册机制
java·spring boot·后端