• 谷粒学苑 —— 8、课程管理:课程发布页面3 —— 信息确认及发布


    目录

    1、确认信息的显示

    1.1、后端

    1.1.1、定义确认信息 VO

    1.1.2、根据课程 ID 获取确认信息

    1.1.3、测试异常:Invalid bound statement (not found)

    1.2、前端

    1.2.1、定义 API

    1.2.2、定义数据模型

    1.2.3、完善步骤导航

    1.2.4、页面组件

    1.2.5、获取确认信息

    2、课程发布

    2.1、后端

    2.1.1、发布指定课程 ID 的课程

    2.2、后端

    2.2.1、定义 API

    2.2.2、发布课程

    3、完整页面


    1、确认信息的显示

    1.1、后端

    1.1.1、定义确认信息 VO

    1. @Data
    2. @ApiModel(value = "课程确认信息")
    3. public class CoursePublishVO {
    4. private String courseId;
    5. private String title;
    6. private String cover;
    7. private Integer lessonNum;
    8. private String subjectLevelOne;
    9. private String subjectLevelTwo;
    10. private String teacherName;
    11. private String price;//只用于显示
    12. }

    1.1.2、根据课程 ID 获取确认信息

    在 EduCourseMapper.xml 添加查询 SQL

    1. <select id="getPublishCourseInfo" resultType="com.zyj.eduservice.entity.vo.CoursePublishVO">
    2. SELECT ec.`id`, ec.`title`, ec.`price`, ec.`lesson_num` AS lessonNum, ec.`cover`,
    3. et.`name` AS teacherName,
    4. es1.`title` AS subjectLevelOne,
    5. es2.`title` AS subjectLevelTwo
    6. FROM `edu_course` ec LEFT OUTER JOIN `edu_teacher` et ON ec.`teacher_id` = et.`id`
    7. LEFT OUTER JOIN `edu_subject` es1 ON ec.`subject_parent_id` = es1.`id`
    8. LEFT OUTER JOIN `edu_subject` es2 ON ec.`subject_id` = es2.`id`
    9. WHERE ec.`id` = '1586554891470389250';
    10. select>

    EduCourseMapper

    1. /**
    2. * 根据课程ID查询课程确认信息
    3. * @param courseId 课程ID
    4. * @return
    5. */
    6. public CoursePublishVO getPublishCourseInfo(String courseId);

    EduCourseService

    1. /**
    2. * 根据课程ID查询课程确认信息
    3. * @param courseId 课程ID
    4. * @return
    5. */
    6. CoursePublishVO publishCourseInfo(String courseId);

    EduCourseServiceImpl

    1. /**
    2. * 根据课程ID查询课程确认信息
    3. * @param courseId 课程ID
    4. * @return
    5. */
    6. @Override
    7. public CoursePublishVO publishCourseInfo(String courseId) {
    8. CoursePublishVO publishCourseInfo = baseMapper.getPublishCourseInfo(courseId);
    9. return publishCourseInfo;
    10. }

    EduCourseController

    1. /**
    2. * 根据课程ID查询课程确认信息
    3. * @param courseId 课程ID
    4. * @return
    5. */
    6. @GetMapping("/getPublishCourseInfo/{courseId}")
    7. public R getPublishCourseInfo(
    8. @ApiParam(name = "courseId", value = "课程ID", required = true) @PathVariable String courseId
    9. ) {
    10. CoursePublishVO coursePublishVO = courseService.publishCourseInfo(courseId);
    11. return R.ok().data("coursePublishVO", coursePublishVO);
    12. }

    1.1.3、测试异常:Invalid bound statement (not found)

    此时测试会报异常 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found),即找不到在 mapper.xml 中定义 SQL 语句。

    这个错误是由 maven 默认加载机制造成的:maven 加载时,只会把 src/main/java 文件夹里面的 .java 类型文件进行编译,如果其他类型文件,不会加载

    解决方法:

    1. 复制 xml 到 target 文件夹(不推荐)
    2. 把 xml 文件放到 resources 目录下(不推荐:破坏项目结构)
    3. (推荐)通过配置实现:在 pom.xml 和 项目 application.properties 中配置

    这里使用第三种方法来解决

    在 service\pom.xml 中配置

    1. <build>
    2. <resources>
    3. <resource>
    4. <directory>src/main/javadirectory>
    5. <includes>
    6. <include>**/*.xmlinclude>
    7. includes>
    8. <filtering>falsefiltering>
    9. resource>
    10. resources>
    11. build>

    然后在 src/main/resources/application.properties 中配置

    1. # 配置mapper xml文件的路径
    2. mybatis-plus.mapper-locations=classpath:com/zyj/eduservice/mapper/xml/*.xml

    配置完后刷新 maven,重启服务,就可以运行了

    1.2、前端

    1.2.1、定义 API

    src\api\edu\course.js

    1. /**
    2. * 根据课程ID查询课程确认信息
    3. * @param {*} courseId
    4. * @returns
    5. */
    6. getPublishCourseInfo(courseId) {
    7. return request({
    8. url: `/eduservice/course/getPublishCourseInfo/${courseId}`,
    9. method: 'GET',
    10. })
    11. }

    并在 src\views\edu\course\publish.vue 中引入

    import course from '@/api/edu/course.js'

    1.2.2、定义数据模型

    1. data() {
    2. return {
    3. saveBtnDisabled: false, // 保存按钮是否禁用
    4. courseId: '', // 课程ID
    5. publishCourse: {} // 课程确认信息
    6. }
    7. },

    1.2.3、完善步骤导航

    1. /**
    2. * 点击上一步跳转到src\views\edu\course\chapter.vue
    3. */
    4. previous() {
    5. this.$router.push({ path: '/course/chapter/' + this.courseId });
    6. },

    1.2.4、页面组件

    显示确认信息

    1. <div class="ccInfo">
    2. <img :src="publishCourse.cover">
    3. <div class="main">
    4. <h2>{{ publishCourse.title }}h2>
    5. <p class="gray"><span>共{{ publishCourse.lessonNum }}课时span>p>
    6. <p><span>所属分类:{{ publishCourse.subjectLevelOne }} — {{ publishCourse.subjectLevelTwo }}span>p>
    7. <p>课程讲师:{{ publishCourse.teacherName }}p>
    8. <h3 class="red">¥{{ publishCourse.price }}h3>
    9. div>
    10. div>

    样式:

    1. <style scoped>
    2. .ccInfo {
    3. background: #f5f5f5;
    4. padding: 20px;
    5. overflow: hidden;
    6. border: 1px dashed #DDD;
    7. margin-bottom: 40px;
    8. position: relative;
    9. }
    10. .ccInfo img {
    11. background: #d6d6d6;
    12. width: 500px;
    13. height: 278px;
    14. display: block;
    15. float: left;
    16. border: none;
    17. }
    18. .ccInfo .main {
    19. margin-left: 520px;
    20. }
    21. .ccInfo .main h2 {
    22. font-size: 28px;
    23. margin-bottom: 30px;
    24. line-height: 1;
    25. font-weight: normal;
    26. }
    27. .ccInfo .main p {
    28. margin-bottom: 10px;
    29. word-wrap: break-word;
    30. line-height: 24px;
    31. max-height: 48px;
    32. overflow: hidden;
    33. }
    34. .ccInfo .main p {
    35. margin-bottom: 10px;
    36. word-wrap: break-word;
    37. line-height: 24px;
    38. max-height: 48px;
    39. overflow: hidden;
    40. }
    41. .ccInfo .main h3 {
    42. left: 540px;
    43. bottom: 20px;
    44. line-height: 1;
    45. font-size: 28px;
    46. color: #d32f24;
    47. font-weight: normal;
    48. position: absolute;
    49. }
    50. style>

    1.2.5、获取确认信息

    在 methods 中定义

    1. /**
    2. * 获取当前课程ID的确认信息
    3. */
    4. getPublishCourseInfo() {
    5. course.getPublishCourseInfo(this.courseId).then(response => {
    6. this.publishCourse = response.data.coursePublishVO;
    7. });
    8. }

    在 created 中获取

    1. created() {
    2. // 获取路由中的课程ID并获取信息
    3. if(this.$route.params && this.$route.params.id) {
    4. this.courseId = this.$route.params.id;
    5. this.getPublishCourseInfo();
    6. }
    7. },

    2、课程发布

    2.1、后端

    2.1.1、发布指定课程 ID 的课程

    EduCourseController

    1. /**
    2. * 发布指定ID的课程:修改课程状态即可
    3. * @param courseId 课程ID
    4. * @return
    5. */
    6. @PostMapping("/publishCourse/{courseId}")
    7. public R publishCourse(
    8. @ApiParam(name = "courseId", value = "课程ID", required = true) @PathVariable String courseId
    9. ) {
    10. EduCourse eduCourse = new EduCourse();
    11. eduCourse.setId(courseId);
    12. eduCourse.setStatus("Normal");
    13. courseService.updateById(eduCourse);
    14. return R.ok();
    15. }

    2.2、后端

    2.2.1、定义 API

    src\api\edu\course.js

    1. /**
    2. * 发布指定ID的课程
    3. * @param {*} courseId 课程ID
    4. * @returns
    5. */
    6. publishCourse(courseId) {
    7. return request({
    8. url: `/eduservice/course/publishCourse/${courseId}`,
    9. method: 'POST'
    10. })
    11. }

    2.2.2、发布课程

    在 methods 中定义

    1. /**
    2. * 发布课程
    3. */
    4. publish() {
    5. this.$confirm('是否发布该课程?', '提示', {
    6. confirmButtonText: '确定',
    7. cancelButtonText: '取消',
    8. type: 'warning'
    9. })
    10. // 确认发布
    11. .then(() => {
    12. course.publishCourse(this.courseId).then(response => {
    13. // 提示信息
    14. this.$message({
    15. type: 'success',
    16. message: '发布成功!'
    17. });
    18. // 跳转到课程列表页面
    19. this.$router.push({ path: '/course/table' })
    20. })
    21. })
    22. // 取消发布
    23. .catch(() => {
    24. this.$message({
    25. type: 'info',
    26. message: '已取消发布'
    27. });
    28. });
    29. }

    3、完整页面

    1. <template>
    2. <div class="app-container">
    3. <h2 style="text-align: center;">发布新课程h2>
    4. <el-steps :active="3" process-status="wait" align-center style="margin-bottom: 40px;">
    5. <el-step title="填写课程基本信息" />
    6. <el-step title="创建课程大纲" />
    7. <el-step title="发布课程" />
    8. el-steps>
    9. <div class="ccInfo">
    10. <img :src="publishCourse.cover">
    11. <div class="main">
    12. <h2>{{ publishCourse.title }}h2>
    13. <p class="gray"><span>共{{ publishCourse.lessonNum }}课时span>p>
    14. <p><span>所属分类:{{ publishCourse.subjectLevelOne }} — {{ publishCourse.subjectLevelTwo }}span>p>
    15. <p>课程讲师:{{ publishCourse.teacherName }}p>
    16. <h3 class="red">¥{{ publishCourse.price }}h3>
    17. div>
    18. div>
    19. <div>
    20. <el-button @click="previous">返回修改el-button>
    21. <el-button :disabled="saveBtnDisabled" type="primary" @click="publish">发布课程el-button>
    22. div>
    23. div>
    24. template>
    25. <script>
    26. import course from '@/api/edu/course.js'
    27. export default {
    28. data() {
    29. return {
    30. saveBtnDisabled: false, // 保存按钮是否禁用
    31. courseId: '', // 课程ID
    32. publishCourse: { // 课程确认信息
    33. }
    34. }
    35. },
    36. created() {
    37. // 获取路由中的课程ID并获取信息
    38. if(this.$route.params && this.$route.params.id) {
    39. this.courseId = this.$route.params.id;
    40. this.getPublishCourseInfo();
    41. }
    42. },
    43. methods: {
    44. /**
    45. * 点击上一步跳转到src\views\edu\course\chapter.vue
    46. */
    47. previous() {
    48. this.$router.push({ path: '/course/chapter/' + this.courseId });
    49. },
    50. /**
    51. * 获取当前课程ID的确认信息
    52. */
    53. getPublishCourseInfo() {
    54. course.getPublishCourseInfo(this.courseId).then(response => {
    55. this.publishCourse = response.data.coursePublishVO;
    56. });
    57. },
    58. /**
    59. * 发布课程
    60. */
    61. publish() {
    62. this.$confirm('是否发布该课程?', '提示', {
    63. confirmButtonText: '确定',
    64. cancelButtonText: '取消',
    65. type: 'warning'
    66. })
    67. // 确认发布
    68. .then(() => {
    69. course.publishCourse(this.courseId).then(response => {
    70. // 提示信息
    71. this.$message({
    72. type: 'success',
    73. message: '课程发布成功!'
    74. });
    75. // 跳转到课程列表页面
    76. this.$router.push({ path: '/course/table' })
    77. })
    78. })
    79. // 取消发布
    80. .catch(() => {
    81. this.$message({
    82. type: 'info',
    83. message: '已取消发布'
    84. });
    85. });
    86. }
    87. }
    88. }
    89. script>
    90. <style scoped>
    91. .ccInfo {
    92. background: #f5f5f5;
    93. padding: 20px;
    94. overflow: hidden;
    95. border: 1px dashed #DDD;
    96. margin-bottom: 40px;
    97. position: relative;
    98. }
    99. .ccInfo img {
    100. background: #d6d6d6;
    101. width: 500px;
    102. height: 278px;
    103. display: block;
    104. float: left;
    105. border: none;
    106. }
    107. .ccInfo .main {
    108. margin-left: 520px;
    109. }
    110. .ccInfo .main h2 {
    111. font-size: 28px;
    112. margin-bottom: 30px;
    113. line-height: 1;
    114. font-weight: normal;
    115. }
    116. .ccInfo .main p {
    117. margin-bottom: 10px;
    118. word-wrap: break-word;
    119. line-height: 24px;
    120. max-height: 48px;
    121. overflow: hidden;
    122. }
    123. .ccInfo .main p {
    124. margin-bottom: 10px;
    125. word-wrap: break-word;
    126. line-height: 24px;
    127. max-height: 48px;
    128. overflow: hidden;
    129. }
    130. .ccInfo .main h3 {
    131. left: 540px;
    132. bottom: 20px;
    133. line-height: 1;
    134. font-size: 28px;
    135. color: #d32f24;
    136. font-weight: normal;
    137. position: absolute;
    138. }
    139. style>

  • 相关阅读:
    VTK OrientationMarker 方向 三维坐标系 相机坐标轴 自定义坐标轴
    C++学习day2
    中国人民大学与加拿大女王大学金融硕士——人生下半场,用实力为自己“撑腰”
    Mybatis如何使用druid数据连接池
    MySQL语法入门
    F.binary_cross_entropy、nn.BCELoss、nn.BCEWithLogitsLoss与F.kl_div函数详细解读
    【疑难】使用ARM development studio仿真 error:Failed to create Jython interpreter
    java程序设计笔记 -- 继承与多态
    野风药业IPO被终止:曾拟募资5.4亿 实控人俞蘠曾进行P2P投资
    屏幕分辨率dpi解析(adb 调试查看)
  • 原文地址:https://blog.csdn.net/Mr_zhangyj/article/details/127691932