实现课程详情接口

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>
相关推荐
红烧大青虫11 小时前
HarmonyOS应用开发实战:小事记 - UIAbility 的冷启动/热启动/后台启动三种场景与 launchParam 解析
后端·华为·harmonyos·鸿蒙系统
码事漫谈11 小时前
AI Token 缓存:命中省 10 倍,不命中白扔钱
后端
65岁退休Coder11 小时前
LangChain v1.3.4 笔记 - 04 Agent 中间件
后端
神奇小汤圆12 小时前
一个接口多个实现,Spring 怎么"适配多场景"?
后端
花开彼岸天~12 小时前
鸿蒙原生开发手记:徒步迹 - 自定义组件开发规范
后端·华为·harmonyos·鸿蒙系统
战族狼魂12 小时前
高频面试题精选:分治与AI Agent架构
人工智能·算法·大模型·大语言模型
李剑一12 小时前
你用过网易的将军令嘛?它底层实现账号保护的原理相当简单粗暴
算法
Scott9999HH12 小时前
告别流量波动玄学!从法拉第电磁定律到底层 C/C++ 流量累积算法,深度解密工业级电磁流量计选型与开发
c语言·c++·算法
songroom13 小时前
Kimi K3:Rust封装XTP接口详细教程实践
开发语言·后端·rust
kebeiovo13 小时前
游戏服务端开发:Actor模型详解(Go语言)
开发语言·后端·golang