ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

发布课程前后端实现

2020-12-06 21:03:48  阅读:168  来源: 互联网

标签:return String 前后 course 发布 课程 id


一 需求

  • 根据课程id获取课程发布基本信息

  • 根据课程id发布课程

二 后端实现

1 定义vo

@Data
public class CoursePublishVo implements Serializable{
    private static final long serialVersionUID = 1L;
    private String id; // 课程id
    private String title; // 标题
    private String cover; // 封面
    private Integer lessonNum; // 课程数
    private String subjectParentTitle; // 一级标题
    private String subjectTitle; // 二级标题
    private String teacherName; // 讲师
    private String price;// 只用于显示
}

2 web层

/**
* 功能描述:根据ID获取课程发布信息
*
* @param id 课程id
* @return R 返回给前端数据
* @author cakin
* @date 2020/12/6
*/
@ApiOperation("根据ID获取课程发布信息")
@GetMapping("course-publish/{id}")
public R getCoursePublishVoById(@ApiParam(value = "课程ID", required = true) @PathVariable String id) {
    CoursePublishVo coursePublishVo = courseService.getCoursePublishVoById(id);
    if (coursePublishVo != null) {
        return R.ok().data("item", coursePublishVo);
    } else {
        return R.error().message("数据不存在");
    }
}

/**
* 功能描述:根据id发布课程
*
* @param id 课程id
* @return R 返回前端数据
* @author cakin
* @date 2020/12/6
*/
@ApiOperation("根据id发布课程")
@PutMapping("publish-course/{id}")
public R publishCourseById(@ApiParam(value = "课程ID", required = true) @PathVariable String id) {
    boolean result = courseService.publishCourseById(id);
    if (result) {
        return R.ok().message("发布成功");
    } else {
        return R.error().message("数据不存在");
    }
}

3 service层

接口

/**
* 功能描述:根据ID获取课程发布信息
*
* @param id 课程id
* @return CoursePublishVo 课程信息
* @author cakin
* @date 2020/12/6
*/
CoursePublishVo getCoursePublishVoById(String id);

/**
* 功能描述:根据id发布课程
*
* @param id 课程id
* @return boolean 是否发布成功
* @author cakin
* @date 2020/12/6
*/
boolean publishCourseById(String id);

实现

/**
* 功能描述:根据ID获取课程发布信息
*
* @param id 课程id
* @return CoursePublishVo 课程信息
* @author cakin
* @date 2020/12/6
*/
@Override
public CoursePublishVo getCoursePublishVoById(String id) {
    return baseMapper.selectCoursePublishVoById(id);
}
/**
* 功能描述:根据id发布课程
*
* @param id 课程id
* @return boolean 是否发布成功
* @author cakin
* @date 2020/12/6
*/
@Override
public boolean publishCourseById(String id) {
    Course course = new Course();
    course.setId(id);
    course.setStatus(Course.COURSE_NORMAL);
    return this.updateById(course);
}

4 mapper层

接口

/**
* 功能描述:根据课程信息获得发布课程
*
* @author cakin
* @date 2020/12/6
* @param id 课程id
* @return CoursePublishVo 课程发布信息
*/
CoursePublishVo selectCoursePublishVoById(String id);

实现

<select id="selectCoursePublishVoById" resultType="com.atguigu.guli.service.edu.entity.vo.CoursePublishVo">
    SELECT
    c.id,
    c.title,
    c.cover,
    c.lesson_num AS lessonNum,
    s1.title AS subjectParentTitle,
    s2.title AS subjectTitle,
    t.name AS teacherName,
    CONVERT(c.price, DECIMAL(8,2)) AS price
    FROM
    <include refid="tables"/>
    WHERE c.id = #{id}
</select>

三 前端代码

1 定义api

  // 根据课程id获得课程发布信息
  getCoursePublishById(id) {
    return request({
      url: `/admin/edu/course/course-publish/${id}`,
      method: 'get'
    })
  },
  // 发布课程
  publishCourseById(id) {
    return request({
      url: `/admin/edu/course/publish-course/${id}`,
      method: 'put'
    })
  }

2 定义数据模型

  data() {
    return {
      publishBtnDisabled: false, // 按钮是否禁用
      coursePublish: {} // 课程发布信息
    }
  },

3 组件方法定义

  // 获取课程发布信息
  created() {
    if (this.$parent.courseId) {
      this.fetchCoursePublishById(this.$parent.courseId)
    }
  },


  methods: {
    // 获取课程发布信息
    fetchCoursePublishById(id) {
      courseApi.getCoursePublishById(id).then(response => {
        this.coursePublish = response.data.item
      })
    },


    // 上一步,跳到第2步
    prev() {
      this.$parent.active = 1
    },


    // 下一步,还在第3步
    publish() {
      this.publishBtnDisabled = true
      courseApi.publishCourseById(this.$parent.courseId).then(response => {
        this.$parent.active = 3
        this.$message.success(response.message)
      })
    }
  }
}

4 组件模板

<template>
  <div class="app-container">
    <!--课程预览-->
    <div class="ccInfo">
      <!-- 封面 -->
      <img :src="coursePublish.cover">
      <!-- 发布内容区 -->
      <div class="main">
        <h2>{{ coursePublish.title }}</h2>
        <p class="gray"><span>共{{ coursePublish.lessonNum }}课时</span></p>
        <p><span>所属分类:{{ coursePublish.subjectParentTitle }} — {{ coursePublish.subjectTitle }}</span></p>
        <p>课程讲师:{{ coursePublish.teacherName }}</p>
        <h3 class="red">¥{{ coursePublish.price }}</h3>
      </div>
    </div>
    <!-- 按钮跳转区 -->
    <div style="text-align:center">
      <el-button type="primary" @click="prev()">上一步</el-button>
      <el-button :disabled="publishBtnDisabled" type="primary" @click="publish()">发布课程</el-button>
    </div>
  </div>
</template>

5 css样式

<style>
.ccInfo {
    background: #f5f5f5;
    padding: 20px;
    overflow: hidden;
    border: 1px dashed #DDD;
    margin-bottom: 40px;
    position: relative;
}
.ccInfo img {
    background: #d6d6d6;
    width: 500px;
    height: 278px;
    display: block;
    float: left;
    border: none;
}
.ccInfo .main {
    margin-left: 520px;
}


.ccInfo .main h2 {
    font-size: 28px;
    margin-bottom: 30px;
    line-height: 1;
    font-weight: normal;
}
.ccInfo .main p {
    margin-bottom: 10px;
    word-wrap: break-word;
    line-height: 24px;
    max-height: 48px;
    overflow: hidden;
}


.ccInfo .main p {
    margin-bottom: 10px;
    word-wrap: break-word;
    line-height: 24px;
    max-height: 48px;
    overflow: hidden;
}
.ccInfo .main h3 {
    left: 540px;
    bottom: 20px;
    line-height: 1;
    font-size: 28px;
    color: #d32f24;
    font-weight: normal;
    position: absolute;
}
</style>

四 测试

 

 

标签:return,String,前后,course,发布,课程,id
来源: https://blog.csdn.net/chengqiuming/article/details/110764141

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有