博客
关于我
删除课程前后端实现
阅读量: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/

你可能感兴趣的文章
Nginx 的配置文件中的 keepalive 介绍
查看>>
nginx 禁止以ip形式访问服务器
查看>>
Nginx 结合 consul 实现动态负载均衡
查看>>
Nginx 负载均衡与权重配置解析
查看>>
Nginx 负载均衡详解
查看>>
nginx 配置 单页面应用的解决方案
查看>>
nginx 配置https(一)—— 自签名证书
查看>>
nginx 配置~~~本身就是一个静态资源的服务器
查看>>
Nginx 配置服务器文件上传与下载
查看>>
Nginx 配置清单(一篇够用)
查看>>
Nginx 配置解析:从基础到高级应用指南
查看>>
Nginx 集成Zipkin服务链路追踪
查看>>
nginx 集群配置方式 静态文件处理
查看>>
nginx+php的搭建
查看>>
nginx+tomcat+memcached
查看>>
Nginx+Tomcat实现动静分离
查看>>
nginx+Tomcat性能监控
查看>>
nginx+uwsgi+django
查看>>
nginx+vsftp搭建图片服务器
查看>>
Nginx-http-flv-module流媒体服务器搭建+模拟推流+flv.js在前端html和Vue中播放HTTP-FLV视频流
查看>>