博客
关于我
删除课程前后端实现
阅读量:202 次
发布时间:2019-02-28

本文共 3107 字,大约阅读时间需要 10 分钟。

一 后端实现

1 控制器

/*** 功能描述:根据ID删除课程** @author cakin* @date 2020/12/6* @param id 课程id* @return R 返回给前端的数据*/@ApiOperation("根据ID删除课程")@DeleteMapping("remove/{id}")public R removeById(@ApiParam(value = "课程id", required = true) @PathVariable String id) {    // TODO: 删除课程视频    // 此处调用vod中的删除视频文件的接口    //删除课程封面    courseService.removeCoverById(id);    // 删除课程    boolean result = courseService.removeCourseById(id);    if (result) {        return R.ok().message("删除成功");    } else {        return R.error().message("数据不存在");    }}

2 service层

接口

/*** 功能描述:删除课程封面** @author cakin* @date 2020/12/6* @param id 课程id* @return boolean 是否删除成功*/boolean removeCoverById(String id);/*** 功能描述:删除课程** @author cakin* @date 2020/12/6* @param id 课程id* @return boolean 是否删除成功*/boolean removeCourseById(String id);

实现

/*** 功能描述:删除课程封面** @param id 课程id* @return boolean 是否删除成功* @author cakin* @date 2020/12/6*/@Overridepublic boolean removeCoverById(String id) {    // 根据id获取课程 Cover 的 url    Course course = baseMapper.selectById(id);    if (course != null) {        String cover = course.getCover();        if (!StringUtils.isEmpty(cover)) {            R r = ossFileService.removeFile(cover);            return r.getSuccess();        }    }    return false;}/*** 功能描述:删除课程** @param id 课程id* @return boolean 是否删除成功* 数据库中外键约束的设置:* 互联网分布式项目中不允许使用外键与级联更新,一切涉及级联的操作不要依赖数据库层,要在业务层解决* 如果业务层解决级联删除功能* 那么先删除子表数据,再删除父表数据* @author cakin* @date 2020/12/6*/@Transactional(rollbackFor = Exception.class)@Overridepublic boolean removeCourseById(String id) {    // 根据 courseId 删除 Video(课时)    QueryWrapper

二 前端实现

1 定义API

// 根据id删除课程  removeById(id) {    return request({      url: `/admin/edu/course/remove/${id}`,      method: 'delete'    })  },

2 修改删除按钮

删除

3 编写删除方法

// 根据id删除数据    removeById(id) {      this.$confirm('此操作将永久删除该课程,以及该课程下的章节和视频,是否继续?', '提示', {        confirmButtonText: '确定',        cancelButtonText: '取消',        type: 'warning'      }).then(() => {        return courseApi.removeById(id)      }).then(response => {        this.fetchData()        this.$message.success(response.message)      }).catch((response) => { // 失败        if (response === 'cancel') {          this.$message.info('取消删除')        }      })    }

三 测试

转载地址:http://phqj.baihongyu.com/

你可能感兴趣的文章
MySQL与Informix数据库中的同义表创建:深入解析与比较
查看>>
mysql与mem_细说 MySQL 之 MEM_ROOT
查看>>
MySQL与Oracle的数据迁移注意事项,另附转换工具链接
查看>>
mysql丢失更新问题
查看>>
MySQL两千万数据优化&迁移
查看>>
MySql中 delimiter 详解
查看>>
MYSQL中 find_in_set() 函数用法详解
查看>>
MySQL中auto_increment有什么作用?(IT枫斗者)
查看>>
MySQL中B+Tree索引原理
查看>>
mysql中cast() 和convert()的用法讲解
查看>>
mysql中datetime与timestamp类型有什么区别
查看>>
MySQL中DQL语言的执行顺序
查看>>
mysql中floor函数的作用是什么?
查看>>
MySQL中group by 与 order by 一起使用排序问题
查看>>
mysql中having的用法
查看>>
MySQL中interactive_timeout和wait_timeout的区别
查看>>
mysql中int、bigint、smallint 和 tinyint的区别、char和varchar的区别详细介绍
查看>>
mysql中json_extract的使用方法
查看>>
mysql中json_extract的使用方法
查看>>
mysql中kill掉所有锁表的进程
查看>>