Kevin's blog Kevin's blog
首页
  • Java基础
  • Java高级
  • MySQL
  • JDBC
  • Java 8新特性
  • 原生Servlet
  • 延迟队列
  • 分布式事务
  • ActiveMQ
  • Elasticsearch
  • Stream API
  • Redis 实战(黑马程序员)
  • Redis 课程(尚硅谷)
  • Redis数据类型和常用命令
  • 版本控制
  • Spring Framework
  • Spring MVC Framework
  • MyBatis Framework
  • MyBatis Plus Framework
  • Spring Boot Framework
  • 韩顺平 Spring Boot Framework
  • 在线教育
  • 谷粒商城 - 分布式基础 高级 集群
  • 谷粒商城 - 详细开发文档
  • docker基础
  • docker-compose容器编排
  • docker swarm集群管理
  • Vue2基础
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • 《Git》
    • TypeScript
    • JS设计模式总结
  • HTML
  • CSS
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Kevin

Java系统笔记
首页
  • Java基础
  • Java高级
  • MySQL
  • JDBC
  • Java 8新特性
  • 原生Servlet
  • 延迟队列
  • 分布式事务
  • ActiveMQ
  • Elasticsearch
  • Stream API
  • Redis 实战(黑马程序员)
  • Redis 课程(尚硅谷)
  • Redis数据类型和常用命令
  • 版本控制
  • Spring Framework
  • Spring MVC Framework
  • MyBatis Framework
  • MyBatis Plus Framework
  • Spring Boot Framework
  • 韩顺平 Spring Boot Framework
  • 在线教育
  • 谷粒商城 - 分布式基础 高级 集群
  • 谷粒商城 - 详细开发文档
  • docker基础
  • docker-compose容器编排
  • docker swarm集群管理
  • Vue2基础
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • 《Git》
    • TypeScript
    • JS设计模式总结
  • HTML
  • CSS
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 项目 在线教育

    • 项目简介

    • Mybatis Plus入门

    • 课程中心微服务搭建

    • 前后端分离相关知识

    • 后台管理系统前端页面的搭建

    • 整合阿里云OSS文件上传

    • 使用POI实现Excel导入导出

    • 整合POI实现课程类目管理

    • 课程基本信息管理

      • 课程发布表单-步骤导航
      • 编辑课程基本信息
      • 课程分类多级联动的实现
      • 讲师下拉列表
      • 富文本编辑器Tinymce
      • 课程封面
      • 课程信息回显
        • 一、后端实现
          • 1、业务层
          • 2、web层
          • 3、Swagger中测试
        • 二、前端实现
          • 1、定义api
          • 2、组件js
        • 三、解决级联下拉菜单回显问题
          • 1、数据库中增加冗余列
          • 2、pojo中增加属性
          • 3、vue组件中绑定数据
          • 4、修改init方法
          • 5、修改fetchCourseInfoById方法
          • 6、金额的显示
      • 更新课程信息
      • 课程列表的显示
      • 删除课程
    • 课程章节信息管理

    • 课程课时管理

    • 使用阿里云视频点播

    • 媒资管理

    • spring cloud服务发现和服务调用

    • 整合ECharts实现统计分析

    • 服务端渲染NUXT

    • 整合阿里云播放器

    • 微服务安全

    • 整合微信登录

    • spring cloud zuul 微服务网关在项目中的应用

    • 总结

  • 项目 谷粒商城

  • 项目 谷粒商城详细开发文档

  • Project
  • 项目 在线教育
  • 课程基本信息管理
zhihuanwang
2023-09-25
目录

课程信息回显

# 一、后端实现

# 1、业务层

接口:CourseService.java

CourseInfoForm getCourseInfoFormById(String id);
1

实现:CourseServiceImpl.java

@Override
public CourseInfoForm getCourseInfoFormById(String id) {

    Course course = this.getById(id);
    if(course == null){
        throw new GuliException(20001, "数据不存在");
    }
    CourseInfoForm courseInfoForm = new CourseInfoForm();
    BeanUtils.copyProperties(course, courseInfoForm);

    CourseDescription courseDescription = courseDescriptionService.getById(id);
    if(course != null){
        courseInfoForm.setDescription(courseDescription.getDescription());
    }

    return courseInfoForm;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# 2、web层

@ApiOperation(value = "根据ID查询课程")
@GetMapping("course-info/{id}")
public R getById(
    @ApiParam(name = "id", value = "课程ID", required = true)
    @PathVariable String id){

    CourseInfoForm courseInfoForm = courseService.getCourseInfoFormById(id);
    return R.ok().data("item", courseInfoForm);
}
1
2
3
4
5
6
7
8
9

# 3、Swagger中测试

# 二、前端实现

# 1、定义api

api/edu/course.js

getCourseInfoById(id) {
    return request({
        url: `${api_name}/course-info/${id}`,
        method: 'get'
    })
}
1
2
3
4
5
6

# 2、组件js

init() {
    if (this.$route.params && this.$route.params.id) {
        const id = this.$route.params.id
        //根据id获取课程基本信息
        this.fetchCourseInfoById(id)
    } 
    
    ......
},
    
fetchCourseInfoById(id) {
  course.getCourseInfoById(id).then(response => {
    this.courseInfo = response.data.item
  }).catch((response) => {
    this.$message({
      type: 'error',
      message: response.message
    })
  })
},
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# 三、解决级联下拉菜单回显问题

# 1、数据库中增加冗余列

subject_parent_id 课程专业父级ID
1

# 2、pojo中增加属性

entity.Course.java

form.CourseInfo.java

@ApiModelProperty(value = "课程专业父级ID")
private String subjectParentId;
1
2

# 3、vue组件中绑定数据

edu/course/infoinfo.vue

<el-select v-model="courseInfo.subjectParentId" ......
1

# 4、修改init方法

将 this.initSubjectList() 和 this.initTeacherList()移至else

init() {
  if (this.$route.params && this.$route.params.id) {
    const id = this.$route.params.id
    // 根据id获取课程基本信息
    this.fetchCourseInfoById(id)
  } else {
    this.courseInfo = { ...defaultForm }
    // 初始化分类列表
    this.initSubjectList()
    // 获取讲师列表
    this.initTeacherList()
  }
},
1
2
3
4
5
6
7
8
9
10
11
12
13

# 5、修改fetchCourseInfoById方法

fetchCourseInfoById(id) {
  course.getCourseInfoById(id).then(responseCourse => {
    this.courseInfo = responseCourse.data.item
    // 初始化分类列表
    subject.getNestedTreeList().then(responseSubject => {
      this.subjectNestedList = responseSubject.data.items
      for (let i = 0; i < this.subjectNestedList.length; i++) {
        if (this.subjectNestedList[i].id === this.courseInfo.subjectParentId) {
          this.subSubjectList = this.subjectNestedList[i].children
        }
      }
    })

    // 获取讲师列表
    this.initTeacherList()
  }).catch((response) => {
    this.$message({
      type: 'error',
      message: response.message
    })
  })
},
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

# 6、金额的显示

金融系统中关于货币的定义

  • 存储精度:4位,根据金额的体量灵活定义,基金类的需要更大的精度
  • 运算精度:8位,一般是存储精度的两倍
  • 显示精度:2位

common中定义常量类

package com.guli.common.constants;
public class PriceConstants {

    public static final int STORE_SCALE = 4; //存储精度
    public static final int CAL_SCALE = 8; //运算精度
    public static final int DISPLAY_SCALE = 2; //显示精度
    public static final BigDecimal ZERO = new BigDecimal("0.0000"); //系统级别的0
}
1
2
3
4
5
6
7
8

service中设置精度

@Override
public CourseInfoForm getCourseInfoFormById(String id) {

    ......

    //设置显示精度:舍弃多余的位数
    courseInfoForm.setPrice(courseInfoForm.getPrice()
                            .setScale(PriceConstants.DISPLAY_SCALE, BigDecimal.ROUND_FLOOR));

    return courseInfoForm;
}
1
2
3
4
5
6
7
8
9
10
11
编辑 (opens new window)
上次更新: 2024/06/15, 15:12:25
课程封面
更新课程信息

← 课程封面 更新课程信息→

最近更新
01
04.Spring Boot 韩顺平
10-12
02
day14
08-29
03
day09
08-29
更多文章>
Theme by Vdoing | Copyright © 2019-2025 Evan Xu | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式