day07項目【課程發(fā)布-添加課程信息】

課程相關(guān)表關(guān)系

01-課程發(fā)布表單-步驟導(dǎo)航

一互躬、需求

二尝胆、配置路由

1嗓奢、添加路由

?{

????path:?'/course',

????component:?Layout,

????redirect:?'/course/list',

????name:?'課程管理',

????meta:?{?title:?'課程管理',?icon:?'example'?},

????children:?[

??????{

????????path:?'list',

????????name:?'課程列表',

????????component:?()?=>?import('@/views/edu/course/list'),

????????meta:?{?title:?'課程列表',?icon:?'table'?}

??????},

??????{

????????path:?'info',

????????name:?'EduCourseInfo',

????????component:?()?=>?import('@/views/edu/course/info'),

????????meta:?{?title:?'發(fā)布課程'?,icon:?'tree'}

??????},

??????{

????????path:?'info/:id',

????????name:?'EduCourseInfoEdit',

????????component:?()?=>?import('@/views/edu/course/info'),

????????meta:?{?title:?'編輯課程基本信息',?noCache:?true?},

????????hidden:?true

??????},

??????{

????????path:?'chapter/:id',

????????name:?'編輯課程大綱',

????????component:?()?=>?import('@/views/edu/course/chapter'),

????????meta:?{?title:?'編輯課程大綱',?icon:?'tree'?},

????????hidden:?true

??????},

??????{

????????path:?'publish/:id',

????????name:?'EduTeacherEdit',

????????component:?()?=>?import('@/views/edu/course/publish'),

????????meta:?{?title:?'發(fā)布課程',?noCache:true?},

????????hidden:true

??????}

????]

??},

2除呵、添加vue組件

三鹉动、整合步驟條組件

參考?http://element-cn.eleme.io/#/zh-CN/component/steps

1轧坎、課程信息頁面

info.vue

<template>

??<div?class="app-container">

????<h2?style="text-align:?center;">發(fā)布新課程</h2>


????<el-steps?:active="1"?process-status="wait"?align-center?style="margin-bottom:?40px;">

??????<el-step?title="填寫課程基本信息"/>

??????<el-step?title="創(chuàng)建課程大綱"/>

??????<el-step?title="最終發(fā)布"/>

????</el-steps>


????<el-form?label-width="120px">

??????<el-form-item>

????????<el-button?:disabled="saveBtnDisabled"?type="primary"?@click="next">保存并下一步</el-button>

??????</el-form-item>

????</el-form>

??</div>

</template>

<script>

export?default?{

????data(){

????????return?{

????????????saveBtnDisabled:?false?//?保存按鈕是否禁用

????????}

????},

????created(){

????},

????methods:{

????????next(){

????????????//跳轉(zhuǎn)到第二步

????????????this.$router.push({path:'/course/chapter/1'})

????????}

????}

}

</script>

2、課程大綱頁面

chapter.vue

<template>

??<div?class="app-container">

????<h2?style="text-align:?center;">發(fā)布新課程</h2>


????<el-steps?:active="2"?process-status="wait"?align-center?style="margin-bottom:?40px;">

??????<el-step?title="填寫課程基本信息"/>

??????<el-step?title="創(chuàng)建課程大綱"/>

??????<el-step?title="最終發(fā)布"/>

????</el-steps>


????<el-form?label-width="120px">

??????<el-form-item>

????????<el-button?@click="previous">上一步</el-button>

????????<el-button?:disabled="saveBtnDisabled"?type="primary"?@click="next">下一步</el-button>

??????</el-form-item>

????</el-form>

??</div>

</template>

<script>

export?default?{

????data(){

????????return?{

????????????saveBtnDisabled:?false?//?保存按鈕是否禁用

????????}

????},

????created(){

????},

????methods:{

????????//上一步

????????previous(){

????????????this.$router.push({path:'/course/info/1'})

????????},

????????next(){

????????????//跳轉(zhuǎn)到第二步

????????????this.$router.push({path:'/course/publish/1'})

????????}

????}

}

</script>

3泽示、課程發(fā)布頁面

publish.vue

<template>

??<div?class="app-container">

????<h2?style="text-align:?center;">發(fā)布新課程</h2>


????<el-steps?:active="3"?process-status="wait"?align-center?style="margin-bottom:?40px;">

??????<el-step?title="填寫課程基本信息"/>

??????<el-step?title="創(chuàng)建課程大綱"/>

??????<el-step?title="最終發(fā)布"/>

????</el-steps>


????<el-form?label-width="120px">

??????<el-form-item>

????????<el-button?@click="previous">返回修改</el-button>

????????<el-button?:disabled="saveBtnDisabled"?type="primary"?@click="publish">發(fā)布課程</el-button>

??????</el-form-item>

????</el-form>

??</div>

</template>

<script>

export?default?{

????data(){

????????return?{

????????????saveBtnDisabled:?false?//?保存按鈕是否禁用

????????}

????},

????created(){

????},

????methods:{

????????previous(){

????????????this.$router.push({path:'/course/chapter/1'})

????????},

????????publish(){

????????????//跳轉(zhuǎn)到第二步

????????????this.$router.push({path:'/course/list'})

????????}

????}

}

</script>


02-編輯課程基本信息

一缸血、后臺api

1蜜氨、定義form表單對象

CourseInfoVo.java

@ApiModel(value = "課程基本信息", description = "編輯課程基本信息的表單對象")

@Data

public class CourseInfoVo implements Serializable {

? ? private static final long serialVersionUID = 1L;

? ? @ApiModelProperty(value = "課程ID")

? ? private String id;

? ? @ApiModelProperty(value = "課程講師ID")

? ? private String teacherId;

? ? @ApiModelProperty(value = "課程專業(yè)ID")

? ? private String subjectId;

? ? @ApiModelProperty(value = "課程標題")

? ? private String title;

? ? @ApiModelProperty(value = "課程銷售價格,設(shè)置為0則可免費觀看")

? ? //0.01

? ? private BigDecimal price;

? ? @ApiModelProperty(value = "總課時")

? ? private Integer lessonNum;

? ? @ApiModelProperty(value = "課程封面圖片路徑")

? ? private String cover;

? ? @ApiModelProperty(value = "課程簡介")

? ? private String description;

}

2捎泻、修改CourseDescription主鍵生成策略

由于課程表和課程簡介表是一對一的關(guān)系飒炎,所以簡介表的id應(yīng)該與課程表的id一致。

3笆豁、定義控制層接口

@RestController

@RequestMapping("/eduservice/course")

@CrossOrigin

public class EduCourseController {

? ? @Autowired

? ? private EduCourseService courseService;

? ? //添加課程基本信息的方法

? ? @ApiOperation(value = "新增課程")

? ? @PostMapping("addCourseInfo")

? ? public R addCourseInfo( @ApiParam(name = "CourseInfoForm", value = "課程基本信息", required = true)

? ? ? ? ? ? @RequestBody CourseInfoVo courseInfoVo){

? ? ? ? courseService.saveCourseInfo(courseInfoVo);

? ? ? ? return R.ok();

? ? }

}

4郎汪、定義業(yè)務(wù)層方法

接口:EduCourseService.java

public interface EduCourseService extends IService<EduCourse> {

? ? //添加課程基本信息的方法

? ? void saveCourseInfo(CourseInfoVo courseInfoVo);

}

實現(xiàn):EduCourseServiceImpl.java

@Service

public class EduCourseServiceImpl extends ServiceImpl<EduCourseMapper, EduCourse> implements EduCourseService {

? ? @Autowired

? ? private EduCourseDescriptionService courseDescriptionService;

? ? @Override

? ? public void saveCourseInfo(CourseInfoVo courseInfoVo) {

? ? ? ? //1 向課程表添加課程基本信息

? ? ? ? //將CourseInfoVo對象轉(zhuǎn)換為eduCourse對象

? ? ? ? EduCourse eduCourse = new EduCourse();

? ? ? ? BeanUtils.copyProperties(courseInfoVo,eduCourse);

? ? ? ? int insert = baseMapper.insert(eduCourse);

? ? ? ? if (insert == 0){

? ? ? ? ? ? //添加失敗

? ? ? ? ? ? throw new GuliException(20001,"添加課程信息失敗");

? ? ? ? }

? ? ? ? //獲取添加之后的課程id

? ? ? ? String cid = eduCourse.getId();


? ? ? ? //2 向課程簡介表添加課程簡介

? ? ? ? //EduCourseDescription

? ? ? ? EduCourseDescription courseDescription = new EduCourseDescription();

? ? ? ? courseDescription.setDescription(courseInfoVo.getDescription());


? ? ? ? //設(shè)置描述id就是課程id

? ? ? ? courseDescription.setId(cid);

? ? ? ? courseDescriptionService.save(courseDescription);

? ? }

}

6、Swagger測試

二渔呵、前端實現(xiàn)

1怒竿、定義api

import?request?from?'@/utils/request'

export?default{

????//1?添加課程信息

????addCourseInfo(courseInfo){

????????return?request({

????????????url:`/eduservice/course/addCourseInfo`,

????????????method:'post',

????????????data:courseInfo

????????})

????}

}

2砍鸠、組件模板

<el-form?label-width="120px">


????????<el-form-item?label="課程標題">

????????????<el-input?v-model="courseInfo.title"?placeholder="?示例:機器學(xué)習(xí)項目課:從基礎(chǔ)到搭建項目視頻課程扩氢。專業(yè)名稱注意大小寫"/>

????????</el-form-item>


????????<!--?所屬分類?TODO?-->


????????<!--?課程講師?TODO?-->


????????<el-form-item?label="總課時">

????????????<el-input-number?:min="0"?v-model="courseInfo.lessonNum"?controls-position="right"?placeholder="請?zhí)顚懻n程的總課時數(shù)"/>

????????</el-form-item>


????????<!--?課程簡介?TODO?-->

????????<el-form-item?label="課程標題">

????????????<el-input?v-model="courseInfo.description"?placeholder="??"/>

????????</el-form-item>

????????<!--?課程封面?TODO?-->

????????<el-form-item?label="課程價格">

????????????<el-input-number?:min="0"?v-model="courseInfo.price"?controls-position="right"?placeholder="免費課程請設(shè)置為0元"/>?元

????????</el-form-item>

????????<el-form-item>

????????????<el-button?:disabled="saveBtnDisabled"?type="primary"?@click="saveOrUpdate">保存并下一步</el-button>

????????</el-form-item>

????</el-form>

3、組件js

<script>

import?course?from?'@/api/edu/course'

export?default?{

????data(){

????????return?{

????????????courseInfo:{

????????????????title:?'',

????????????????subjectId:?'',

????????????????teacherId:?'',

????????????????lessonNum:?0,

????????????????description:?'',

????????????????cover:?'',

????????????????price:?0,

????????????},

????????????saveBtnDisabled:?false?//?保存按鈕是否禁用

????????}

????},

????created(){

????},

????methods:{

????????saveOrUpdate(){

????????????course.addCourseInfo(this.courseInfo)

????????????????.then(response=>{

????????????????????//提示

????????????????????this.$message({

?????????????????????????type:?'success',

?????????????????????????message:?'添加課程信息成功!'

????????????????????});

????????????????????//跳轉(zhuǎn)到第二步

????????????????????this.$router.push({path:'/course/chapter/'+response.data.courseId})

????????????????})

????????},

????}

}

</script>



03-課程分類多級聯(lián)動的實現(xiàn)

一爷辱、需求

二录豺、獲取一級分類

1、組件數(shù)據(jù)定義

定義在data中

? ? ? ? ? ? subjectOneList:[],//一級分類

????????????subjectTwoList:[],//二級分類

2饭弓、組件模板

<!--?所屬分類?TODO?-->

????????<el-form-item?label="課程分類">

????????????<el-select

????????????????v-model="courseInfo.subjectParentId"

????????????????placeholder="一級分類">

????????????????<el-option

????????????????????v-for="subject?in?subjectOneList"

????????????????????:key="subject.id"

????????????????????:label="subject.title"

????????????????????:value="subject.id"/>

????????????</el-select>

????</el-form-item>

3双饥、組件腳本

表單初始化時獲取一級分類嵌套列表,引入subject api

import?subject?from?'@/api/edu/subject'

定義方法

????????//獲取一級分類

????????getOneSubjectList(){

????????????subject.getSubjectList()

????????????????.then(response=>{

????????????????????this.subjectOneList?=?response.data.list

????????????????})

????????},

三弟断、級聯(lián)顯示二級分類

1咏花、組件模板

????????????<!--?二級分類?-->

????????????<el-select?v-model="courseInfo.subjectId"?placeholder="二級分類">

????????????????<el-option

????????????????????v-for="subject?in?subjectTwoList"

????????????????????:key="subject.id"

????????????????????:label="subject.title"

????????????????????:value="subject.id"/>

????????????</el-select>

2、注冊change事件

在一級分類的<el-select>組件中注冊change事件

????????<!--?所屬分類?TODO?-->

????????<el-form-item?label="課程分類">

????????????<el-select

????????????????v-model="courseInfo.subjectParentId"

????????????????placeholder="一級分類"?@change="subjectLevelOneChanged">

? ? ? ? ? ? ?? .......

????????????</el-select>

3阀趴、定義change事件方法

????????//點擊某一個一級分類昏翰,觸發(fā)change事件,顯示對應(yīng)二級分類

????????subjectLevelOneChanged(value){

????????????//value就是一級分類id值

????????????//遍歷所有的分類刘急,包含一級和二級

????????????for(var?i?=0;?i<this.subjectOneList.length;i++){

????????????????//每一個一級分類

????????????????var?oneSubject?=?this.subjectOneList[i]

????????????????//判斷:所有一級分類id和點擊一級分類id是否一樣

????????????????if(oneSubject.id?===?value){

????????????????????//從一級分類獲取里面所有的二級分類

????????????????????this.subjectTwoList?=?oneSubject.children

????????????????????//把二級分類id值清空

????????????????????this.courseInfo.subjectId?=?''

????????????????}

????????????}

????????},


04-講師下拉列表

一棚菊、前端實現(xiàn)

1、組件模板

????????<!--?課程講師?TODO?-->

????????<!--?課程講師?-->

????????<el-form-item?label="課程講師">

????????????<el-select

????????????????v-model="courseInfo.teacherId"

????????????????placeholder="請選擇">

????????????????<el-option

????????????????????v-for="teacher?in?teacherList"

????????????????????:key="teacher.id"

????????????????????:label="teacher.name"

????????????????????:value="teacher.id"/>

????????????</el-select>

????????</el-form-item>

2叔汁、定義api

api/edu/course.js

//2?查詢所有講師

????getListTeacher(){

????????return?request({

????????????url:`/eduservice/teacher/findAll`,

????????????method:'get'

????????})

????}

組件中引入course api

import?course?from?'@/api/edu/course'

3统求、組件腳本

定義data

teacherList:[],//講師列表

獲取講師列表:

????????//查詢所有講師

????????getListTeacher(){

????????????course.getListTeacher()

????????????????.then(response?=>?{

????????????????????this.teacherList?=?response.data.items

????????????????})

????????}

??created(){

????????//初始化所有講師

????????this.getListTeacher()

????},


05-富文本編輯器Tinymce

一、Tinymce可視化編輯器

參考

https://panjiachen.gitee.io/vue-element-admin/#/components/tinymce

https://panjiachen.gitee.io/vue-element-admin/#/example/create

二据块、組件初始化

Tinymce是一個傳統(tǒng)javascript插件码邻,默認不能用于Vue.js因此需要做一些特殊的整合步驟

1、復(fù)制腳本庫

將腳本庫復(fù)制到項目的static目錄下(在vue-element-admin-master的static路徑下)

2另假、配置html變量

在 guli-admin/build/webpack.dev.conf.js 中添加配置

使在html頁面中可是使用這里定義的BASE_URL變量

3冒滩、引入js腳本

在guli-admin/index.html 中引入js腳本

????<script?src=<%=?BASE_URL?%>/tinymce4.7.5/tinymce.min.js></script>

????<script?src=<%=?BASE_URL?%>/tinymce4.7.5/langs/zh_CN.js></script>

三、組件引入

為了讓Tinymce能用于Vue.js項目浪谴,vue-element-admin-master對Tinymce進行了封裝开睡,下面我們將它引入到我們的課程信息頁面

1因苹、復(fù)制組件

src/components/Tinymce

2、引入組件

課程信息組件中引入 Tinymce

import?Tinymce?from?'@/components/Tinymce' //引用

export?default?{

????components:?{?Tinymce?}, //聲明

? ? .......

}

3篇恒、組件模板

???????<!--?課程簡介-->

????????<el-form-item?label="課程簡介">

????????????<tinymce?:height="300"?v-model="courseInfo.description"/>

????????</el-form-item>

4扶檐、組件樣式

在info.vue文件的最后添加如下代碼,調(diào)整上傳圖片按鈕的高度

<style?scoped>/*?scoped表示只在當(dāng)前頁面有效?*/????

????.tinymce-container?{

????????line-height:?29px;

????}

</style>

5胁艰、圖片的base64編碼

Tinymce中的圖片上傳功能直接存儲的是圖片的base64編碼款筑,因此無需圖片服務(wù)器

測試:

添加一級分類id:



06-課程封面

一、整合上傳組件

參考?http://element-cn.eleme.io/#/zh-CN/component/upload用戶頭像上傳

1腾么、定義data數(shù)據(jù)

BASE_API:?process.env.BASE_API,?//?接口API地址

2奈梳、組件模板

在info.vue中添加上傳組件模板

????????<!--?課程封面-->

????????<el-form-item?label="課程封面">?????????


????????????<el-upload

????????????????:show-file-list="false"

????????????????:on-success="handleAvatarSuccess"

????????????????:before-upload="beforeAvatarUpload"

????????????????:action="BASE_API+'/eduoss/fileoss'"

????????????????class="avatar-uploader">

????????????<img?:src="courseInfo.cover">

????????</el-upload>

5、結(jié)果回調(diào)

????????//上傳封面成功

????????handleAvatarSuccess(res,?file){

????????????this.courseInfo.cover?=?res.data.url

????????},

????????//上傳封面之前

????????beforeAvatarUpload(file){

????????????const?isJPG?=?file.type?===?'image/jpeg'

????????????const?isLt2M?=?file.size?/?1024?/?1024?<?2


????????????if?(!isJPG)?{

????????????????this.$message.error('上傳頭像圖片只能是?JPG?格式!')

????????????}

????????????if?(!isLt2M)?{

????????????????this.$message.error('上傳頭像圖片大小不能超過?2MB!')

????????????}

????????????return?isJPG?&&?isLt2M

????????},




07-課程信息回顯

一解虱、后端實現(xiàn)

1攘须、業(yè)務(wù)層

接口:CourseService.java

//根據(jù)ID查詢課程

CourseInfoVo getCourseInfoFormById(String courseId);

實現(xiàn):CourseServiceImpl.java

@Override

? ? public CourseInfoVo getCourseInfoFormById(String courseId) {

? ? ? ? //1 查詢課程表

? ? ? ? EduCourse eduCourse = baseMapper.selectById(courseId);

//? ? ? ? EduCourse eduCourse = this.getById(courseId);

? ? ? ? if (eduCourse == null){

? ? ? ? ? ? throw new GuliException(20001, "數(shù)據(jù)不存在");

? ? ? ? }

? ? ? ? //把eduCourse對象中的值復(fù)制到courseInfoVo中

? ? ? ? CourseInfoVo courseInfoVo = new CourseInfoVo();

? ? ? ? BeanUtils.copyProperties(eduCourse,courseInfoVo);


? ? ? ? //2 查詢描述表

? ? ? ? EduCourseDescription courseDescription = courseDescriptionService.getById(courseId);

? ? ? ? if (eduCourse !=null){

? ? ? ? ? ? //講描述信息放入courseInfoVo

? ? ? ? ? ? courseInfoVo.setDescription(courseDescription.getDescription());

? ? ? ? }

? ? ? ? return courseInfoVo;

? ? }

2、web層

????@ApiOperation(value = "根據(jù)ID查詢課程")

? ? @GetMapping("getCourseInfo/{courseId}")

? ? public R getCourseInfo(@ApiParam(name = "id", value = "課程ID", required = true)

? ? ? ? ? ? ? ? ? ? ? ? @PathVariable String courseId){

? ? ? CourseInfoVo courseInfoVo? = courseService.getCourseInfoFormById(courseId);

? ? ? ? return R.ok().data("courseInfoVo",courseInfoVo);

? ? }

3殴泰、Swagger中測試

二于宙、前端實現(xiàn)

1、定義api

api/edu/course.js

?//3?根據(jù)id獲取課程基本信息

????getCourseInfoById(id){

????????return?request({

????????????url:`/eduservice/course/getCourseInfo/${id}`,

????????????method:'get'????????????

????????})

????},

2悍汛、組件js

data中聲明:

??courseId:'',

created()

????//獲取路由中的路由id值

????????if(this.$route.params?&&?this.$route.params.id){

????????????this.courseId?=?this.$route.params.id

????????????//調(diào)用

????????????this.getInfo()

????????}

方法:

????//根據(jù)id獲取課程信息

????????getInfo(){

????????????course.getCourseInfoById(this.courseId)

????????????????.then(response?=>?{

????????????????????this.courseInfo?=?response.data.courseInfoVo

????????????????})

????????},

三捞魁、解決級聯(lián)下拉菜單回顯問題

1、數(shù)據(jù)庫中增加冗余列

subject_parent_id課程專業(yè)父級ID

2离咐、pojo中增加屬性

entity.Course.java

form.CourseInfo.java

@ApiModelProperty(value = "一級分類ID")

? ? private String subjectParentId;

3谱俭、vue組件中綁定數(shù)據(jù)

edu/course/info.vue

4、修改init方法

將?this.initSubjectList() 和 this.initTeacherList()移至else

????????//init方法

????????init(){

?????????????//獲取路由中的路由id值

????????????if(this.$route.params?&&?this.$route.params.id){

????????????????this.courseId?=?this.$route.params.id

????????????????//調(diào)用

????????????????this.getInfo()

????????????}else{

????????????????//清空表單

????????????????this.courseInfo?=?{...defaultForm}

????????????????//初始化所有講師

????????????????this.getListTeacher()

????????????????//初始化一級分類

????????????????this.getOneSubjectList()

????????????}

????????},

5宵蛀、修改fetchCourseInfoById方法

解決在返回上一步的二級表單的問題昆著。

????//根據(jù)id獲取課程信息

????????getInfo(){

????????????course.getCourseInfoById(this.courseId)

????????????????.then(response?=>?{

????????????????????this.courseInfo?=?response.data.courseInfoVo

????????????????????//1?查詢所有的分類,包含一級和二級

????????????????????subject.getSubjectList()

????????????????????????.then(response=>{

????????????????????????????//2?獲取所有一級分類

????????????????????????????this.subjectOneList?=?response.data.list

????????????????????????????//3?把所有的一級分類數(shù)組進行遍歷

????????????????????????????for(var?i=0;i<this.subjectOneList.length;?i++){

????????????????????????????????//獲取每一個一級分類

????????????????????????????????var?subjectOne?=?this.subjectOneList[i]

????????????????????????????????//比較當(dāng)前courseInfo里面的一級分類id和所有的一級分類id

????????????????????????????????if(this.courseInfo.subjectParentId?==?subjectOne.id){

????????????????????????????????????//獲取一級分類里面的所有二級分類

????????????????????????????????????this.subjectTwoList?=?subjectOne.children

????????????????????????????????}

????????????????????????????}

????????????????????????})

????????????????????????//初始化所有講師

????????????????????????this.getListTeacher()

????????????????})

????????},

刷新發(fā)布課程頁面:

const?defaultForm?=?{

????title:?'',

????subjectId:?'',//二級分類id

????subjectParentId:'',//一級分類id

????teacherId:?'',

????lessonNum:?0,

????description:?'',

????cover:?'/static/11.jpg',

????price:?0

}

?created(){

???????this.init()

????},

????????//init方法

????????init(){

?????????????//獲取路由中的路由id值

????????????if(this.$route.params?&&?this.$route.params.id){

????????????????this.courseId?=?this.$route.params.id

????????????????//調(diào)用

????????????????this.getInfo()

????????????}else{

????????????????//清空表單

????????????????this.courseInfo?=?{...defaultForm}

????????????????//初始化所有講師

????????????????this.getListTeacher()

????????????????//初始化一級分類

????????????????this.getOneSubjectList()

????????????}

????????},


????//監(jiān)聽

????watch:{

????????$route(to,from){?//路由變化方式糖埋,路由發(fā)生變化宣吱,方法就會執(zhí)行

????????????this.init()

????????}

????},



08-更新課程信息

一、后端實現(xiàn)

1瞳别、業(yè)務(wù)層

接口:EduCourseService.java

????//更新課程信息

? ? void updateCourseInfoById(CourseInfoVo courseInfoVo);

實現(xiàn):EduCourseServiceImpl.java

????//更新課程信息

? ? @Override

? ? public void updateCourseInfoById(CourseInfoVo courseInfoVo) {

? ? ? ? //1 修改課程表

? ? ? ? EduCourse eduCourse = new EduCourse();

? ? ? ? BeanUtils.copyProperties(courseInfoVo,eduCourse);

? ? ? ? int update = baseMapper.updateById(eduCourse);

? ? ? ? if (update == 0){

? ? ? ? ? ? throw new GuliException(20001,"修改課程信息失敗");

? ? ? ? }

? ? ? ? //2 修改描述表

? ? ? ? EduCourseDescription courseDescription = new EduCourseDescription();

? ? ? ? courseDescription.setId(courseInfoVo.getId());

????????courseDescription.setDescription(courseInfoVo.getDescription());

? ? ? ? courseDescriptionService.updateById(courseDescription);

? ? }

2征候、web層

????//更新課程信息

? ? @ApiOperation(value = "更新課程")

? ? @PostMapping("updateCourseInfo")

? ? public R updateCourseInfo( @ApiParam(name = "CourseInfoForm", value = "課程基本信息", required = true)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @RequestBody CourseInfoVo courseInfoVo){

? ? ? ? courseService.updateCourseInfoById(courseInfoVo);

? ? ? ? return R.ok();

? ? }

二、前端實現(xiàn)

1祟敛、定義api

course.js

?//4?修改課程基本信息

????updateCourseInfoById(courseInfo){

????????return?request({

????????????url:`/eduservice/course/updateCourseInfo`,

????????????method:'post',

????????????data:courseInfo

????????})

????}

2疤坝、組件js

info.vue

?updateCourse(){

????????????course.updateCourseInfoById(this.courseInfo)

????????????????.then(response=>{

????????????????????//提示

????????????????????this.$message({

?????????????????????????type:?'success',

?????????????????????????message:?'修改課程信息成功!'

????????????????????});

????????????????????//跳轉(zhuǎn)到第二步

????????????????????this.$router.push({path:'/course/chapter/'+this.courseId})

????????????????})

????????},

?saveOrUpdate(){

???????????if(!this.courseInfo.id){

???????????????//添加

???????????????this.addCourse()

???????????}else{

???????????????//修改

???????????????this.updateCourse()

???????????}

????????},

403錯誤

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市馆铁,隨后出現(xiàn)的幾起案子跑揉,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,544評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件历谍,死亡現(xiàn)場離奇詭異现拒,居然都是意外死亡,警方通過查閱死者的電腦和手機望侈,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評論 3 392
  • 文/潘曉璐 我一進店門印蔬,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人脱衙,你說我怎么就攤上這事侥猬。” “怎么了捐韩?”我有些...
    開封第一講書人閱讀 162,764評論 0 353
  • 文/不壞的土叔 我叫張陵退唠,是天一觀的道長。 經(jīng)常有香客問我荤胁,道長瞧预,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,193評論 1 292
  • 正文 為了忘掉前任寨蹋,我火速辦了婚禮松蒜,結(jié)果婚禮上扔茅,老公的妹妹穿的比我還像新娘已旧。我一直安慰自己,他們只是感情好召娜,可當(dāng)我...
    茶點故事閱讀 67,216評論 6 388
  • 文/花漫 我一把揭開白布运褪。 她就那樣靜靜地躺著,像睡著了一般玖瘸。 火紅的嫁衣襯著肌膚如雪秸讹。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,182評論 1 299
  • 那天雅倒,我揣著相機與錄音璃诀,去河邊找鬼。 笑死蔑匣,一個胖子當(dāng)著我的面吹牛劣欢,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播裁良,決...
    沈念sama閱讀 40,063評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼凿将,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了价脾?” 一聲冷哼從身側(cè)響起牧抵,我...
    開封第一講書人閱讀 38,917評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后犀变,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體妹孙,經(jīng)...
    沈念sama閱讀 45,329評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,543評論 2 332
  • 正文 我和宋清朗相戀三年获枝,在試婚紗的時候發(fā)現(xiàn)自己被綠了涕蜂。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,722評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡映琳,死狀恐怖机隙,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情萨西,我是刑警寧澤有鹿,帶...
    沈念sama閱讀 35,425評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站谎脯,受9級特大地震影響葱跋,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜源梭,卻給世界環(huán)境...
    茶點故事閱讀 41,019評論 3 326
  • 文/蒙蒙 一娱俺、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧废麻,春花似錦荠卷、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,671評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至怜姿,卻和暖如春慎冤,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背沧卢。 一陣腳步聲響...
    開封第一講書人閱讀 32,825評論 1 269
  • 我被黑心中介騙來泰國打工蚁堤, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人但狭。 一個月前我還...
    沈念sama閱讀 47,729評論 2 368
  • 正文 我出身青樓披诗,卻偏偏與公主長得像,于是被迫代替她去往敵國和親熟空。 傳聞我的和親對象是個殘疾皇子藤巢,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,614評論 2 353