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

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

后端实现

1. 控制器

功能描述:根据ID删除课程

编写人:cakin

日期:2020/12/6
参数:id 课程id
返回:R 返回给前端的数据

@ApiOperation("根据ID删除课程")@DeleteMapping("remove/{id}")public R removeById(@ApiParam(value = "课程id", required = true) @PathVariable String id) {    // 删除课程视频    courseService.removeCoverById(id);    // 删除课程    boolean result = courseService.removeCourseById(id);    if (result) {        return R.ok().message("删除成功");    } else {        return R.error().message("数据不存在");    }}

2. 服务层

接口

功能描述:删除课程封面

编写人:cakin

日期:2020/12/6
参数:id 课程id
返回:boolean 是否删除成功

功能描述:删除课程

编写人:cakin

日期:2020/12/6
参数:id 课程id
返回:boolean 是否删除成功

实现

@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;}@Override@Transactional(rollbackFor = Exception.class)public boolean removeCourseById(String id) {    // 根据 courseId 删除 Video(课时)    QueryWrapper

3. 前端实现

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/

你可能感兴趣的文章
OPC在工控上位机中的应用
查看>>
VSCode在终端中使用yarn命令
查看>>
OPEN CASCADE Curve Continuity
查看>>
Open Graph Protocol(开放内容协议)
查看>>
Open vSwitch实验常用命令
查看>>
Open WebUI 忘了登入密码怎么办?
查看>>
open***负载均衡高可用多种方案实战讲解02(老男孩主讲)
查看>>
Open-E DSS V7 应用系列之五 构建软件NAS
查看>>
Open-Sora代码详细解读(1):解读DiT结构
查看>>
Open-Sora代码详细解读(2):时空3D VAE
查看>>
Open-Source Service Discovery
查看>>
open-vm-tools-dkms : 依赖: open-vm-tools (>= 2:9.4.0-1280544-5ubuntu3) 但是它将不会被安装
查看>>
open3d-Dll缺失,未找到指定模块解决
查看>>
openai Midjourney代理服务 gpt大模型第三方api平台汇总 支持国内外各种大模型 持续更新中...
查看>>
OpenAll:Android打开组件新姿势【仅供用于学习了解ButterKnife框架基本原理】
查看>>
OpenASR 项目使用教程
查看>>
Openbox-桌面图标设置
查看>>
opencart出现no such file or dictionary
查看>>
OpenCV 3.1 imwrite()函数写入异常问题解决方法
查看>>
OpenCV 4.1.0版drawContours
查看>>