当前位置: 首页 > news >正文

spring boot 配合element ui vue实现表格的批量删除(前后端详细教学,简单易懂,有手就行)

目录

一.前言:

二. 前端代码:

2.1.element ui组件代码

 

2.2删除按钮

2.3.data

2.4.methods

三.后端代码:


一.前言:

研究了其他人的博客,找到了一篇有含金量的,进行了部分改写实现前后端分离,参考博主为小白Rachel

先看看页面效果,要是符合你们所需的功能那就继续看下去

 

 

 

 

1406 1407 被干掉了 

二. 前端代码:

2.1.element ui组件代码

想要实现勾选框那么就需要加上 

<el-table-column type="selection" width="55" align="center" />

加入事件。该事件可用于获取勾选到的那一行数据的id,如果勾选多行数据,那么就会将id打包成数组,我们就可以将数组传给后端,然后由Java程序员(还是我)进行接收,进行批量删除。

@selection-change="handleSelectionChange"

 

 <el-table:data="operLogs"style="width: 100%"@selection-change="handleSelectionChange"><el-table-column type="selection" width="55" align="center" /><template><!-- `checked` 为 true 或 false --><el-checkbox v-model="checked">备选项</el-checkbox></template><el-table-columnlabel="日志编号"width="140"><template slot-scope="scope"><i class="el-icon-time"></i><span style="margin-left: 10px">{{ scope.row.operId }}</span></template></el-table-column>

 

 

2.2删除按钮

        <el-popconfirmconfirm-button-text='好的'cancel-button-text='取消'icon="el-icon-info"icon-color="red"@confirm="handleDelete()"title="确定删除吗?"><el-button type="danger" round size="mini" slot="reference" :disabled="multiple">删除</el-button></el-popconfirm>

:disabled="multiple"

设置状态默认为true 代表禁用了。

2.3.data

data() {return {
// 选中数组ids: [],
// 非单个禁用single: true,
// 非多个禁用multiple: true,}},

 因为我的data里面的数据太多,所以我就进行了删减,把实现批量删除的数据给列了出来。

2.4.methods

// 多选框选中数据handleSelectionChange(selection) {console.log(selection);this.ids = selection.map(item => item.operId);// 需要根据数据情况调整id名称console.log(this.ids);this.single = selection.length != 1;this.multiple = !selection.length;},handleDelete() {//传数组进行批量删除this.axios.post("http://localhost:8080/operLog", this.ids).then(result => {if (result.data.status == "OK") {this.loadOperLogByPage(this.current);}})},
// 多选框选中数据handleSelectionChange(selection) {console.log(selection);this.ids = selection.map(item => item.operId);// 需要根据数据情况调整id名称console.log(this.ids);this.single = selection.length != 1;this.multiple = !selection.length;},

如果选中了数据,就修改mulitple的属性为false,改变button的disabled为false,代表可以勾选

handleDelete() {//传数组进行批量删除this.axios.post("http://localhost:8080/operLog", this.ids).then(result => {if (result.data.status == "OK") {this.loadOperLogByPage(this.current);}})
},

懂得都懂

 

三.后端代码:

    @PostMapping("/operLog")public ResponseResult<String> deleteByIds(@RequestBody List<Long> operIds){System.out.println(operIds);int i = operLogService.deleteByIds(operIds);if (i==1){return ResponseResult.ok("删除成功");}else {return ResponseResult.ok("删除失败");}}

执行批量删除,一行搞定

http://www.lryc.cn/news/24158.html

相关文章:

  • hiveSQL开窗函数详解
  • 深度学习基础实例与总结
  • 在 WIndows 下安装 Apache Tinkerpop (Gremlin)
  • 从软件的角度看待PCI和PCIE(一)
  • DSP_TMS320F28377D_ADC学习笔记
  • springcloud3 Nacos中namespace和group,dataId的联系
  • [YOLO] yolo理解博客笔记
  • 清华源pip安装Python第三方包
  • python线程池【ThreadPoolExecutor()】批量获取博客园标题数据
  • LearnOpenGL-入门-8.坐标系统
  • windows10使用wsl2安装docker
  • Javascript的API基本内容(六)
  • 电压放大器和电流放大器的区别是什么意思
  • cast提前!最简单有效的神经网络优化方法,没有之一!
  • LeetCode刷题——动态规划(C/C++)
  • 车载智能终端TBOX
  • 技术分担产品之忧(上):挑选有业务专家潜力的人
  • UVa 12569 Planning mobile robot on Tree (EASY Version) 树上机器人规划(简单版) BFS 二进制
  • intel的集成显卡(intel(r) uhd graphics) 配置stable diffusion
  • 【数据库的基础知识(2)】
  • Docker部署实战
  • RestTemplate 相关使用
  • 新手小白亚马逊注册最全教程在此
  • 二分查找重复情况 找最左边或最右边的位置下标
  • 智慧扫码点餐系统源码
  • 分布式环境并发场景下,如何操作抢红包(或者减少库存)
  • 明星的孩子也在做的感统训练,真的有用吗?
  • 守护进程与TCP通讯
  • 在线文本翻译能力新增14个直译模型,打造以中文为轴心语言的翻译系统
  • CVE-2022-42889 Apache Commons Text 漏洞