Java實(shí)現(xiàn)多選批量刪除功能(vue+Element)
本文實(shí)例為大家分享了Java實(shí)現(xiàn)多選批量刪除功能的具體代碼,供大家參考,具體內(nèi)容如下
選擇前效果圖

選中效果圖

前端vue代碼
1、頁面顯示template
使用方法 @selection-change=“changeFun” 獲取表中選中的行所有顯示的數(shù)據(jù)
<template>
<div class="dept tab-container">
<div class="dept-table">
<div id="query" class="newTable">
<!-- 列表數(shù)據(jù)展示-->
<el-table
:data="list"
border
fit
style="width: 100%;"
v-loading="loading"
element-loading-text="請(qǐng)給我點(diǎn)時(shí)間!"
@selection-change="changeFun"
>
<el-table-column type="selection" width="55" v-model="checkBoxData"></el-table-column>
<el-table-column align="center" label="姓名" min-width="60px">
<template slot-scope="scope">
<span>{{scope.row.name }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="記錄類型" min-width="80px">
<template slot-scope="scope">
<span>{{getTypeName(scope.row.type)}}</span>
</template>
</el-table-column>
<el-table-column align="center" label="返回信息" min-width="180px">
<template slot-scope="scope">
<span>{{scope.row.message }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="創(chuàng)建人">
<template slot-scope="scope">
<span>{{scope.row.createUserId}}</span>
</template>
</el-table-column>
<el-table-column align="center" label="創(chuàng)建時(shí)間" min-width="55px">
<template slot-scope="scope">
<span>{{parseTime(scope.row.createDateTime)}}</span>
</template>
</el-table-column>
<el-table-column align="center" label="最后修改人">
<template slot-scope="scope">
<span>{{scope.row.modifyUserId}}</span>
</template>
</el-table-column>
<el-table-column align="center" label="最后修改時(shí)間" min-width="55px">
<template slot-scope="scope">
<span>{{parseTime(scope.row.modifyDateTime)}}</span>
</template>
</el-table-column>
<el-table-column class-name="status-col" min-width="100px" label="操作">
<template slot-scope="scope">
<el-button class="btn" size="mini" type="danger" @click="delHandle(scope.row.id)" v-if="isButtonShow('userDel')">刪除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 批量刪除-->
<br />
<div style="float: left;">
<el-button class="btn" size="mini" :disabled="btnChangeEnable" @click="delBatchHandle" type="danger">批量刪除</el-button>
</div>
<br />
<!--分頁 begin-->
<div class="pagination-container">
<el-row>
<el-col :span="19">
<el-pagination
background
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="listQuery.current"
:page-sizes="[10,20,30, 50]"
:page-size="listQuery.size"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
></el-pagination>
</el-col>
</el-row>
</div>
<!--分頁 end-->
</div>
</div>
</div>
</template>
2、定義顯示值
data(){
return{
btnChangeEnable: true, // 批量刪除禁用
checkBoxData: [], //多選框選擇的值
}
}
3、選中時(shí)觸發(fā)方法
@selection-change=“changeFun”
// 獲取多選框選中的值
changeFun(val) {
console.log(val)
this.checkBoxData = val;
if(val == ''){
this.btnChangeEnable = true;
} else {
this.btnChangeEnable = false;
}
},
4、批量刪除按鈕綁定事件
<el-button class="btn" size="mini" :disabled="btnChangeEnable" @click="delBatchHandle" type="danger">批量刪除</el-button>
5、觸發(fā)事件
導(dǎo)入 axios
import axios from 'axios';
// 批量刪除
delBatchHandle() {
this.$confirm('確定要?jiǎng)h除嗎?', '提示', {
confirmButtonText: '確定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// 解析checkBoxData中的id值,也可以解析其他包含的數(shù)據(jù)
var ids = this.checkBoxData.map(item => item.id).join()//獲取所有選中行的id組成的字符串,以逗號(hào)分隔
console.log(ids)
axios.post("/verityRecord/deleteBatch", { vrDatas: ids }).then((result) => {
if (result.code == '0000') {
this.$message({
type: 'success',
message: '操作成功!'
})
this.getList()
} else {
this.$message({
type: 'error',
message: '操作失敗!'
})
}
})
}).catch(() => {
this.$message({
type: 'info',
message: '已取消操作'
})
})
}
后臺(tái)接收并解析
/**
* 批量刪除信息
* <p>
* author:
* @param paramsMap
* @return
*/
@RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
public void deleteBatch(@RequestBody Map<String, Object> paramsMap) {
if (paramsMap != null && paramsMap.size() > 0) {
String vrDatas = paramsMap.get("vrDatas").toString();
String[] ids = vrDatas.split(",");
for (String id : ids) {
// 根據(jù)自己的service方法邏輯處理
}
}
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
java遠(yuǎn)程連接Linux執(zhí)行命令的3種方式完整代碼
在一些Java應(yīng)用程序中需要執(zhí)行一些Linux系統(tǒng)命令,例如服務(wù)器資源查看、文件操作等,這篇文章主要給大家介紹了關(guān)于java遠(yuǎn)程連接Linux執(zhí)行命令的3種方式,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-06-06
JAVA中try-catch結(jié)構(gòu)之異常處理的使用方法
Java編程中一個(gè)非常重要且實(shí)用的概念,可以幫助我們處理代碼運(yùn)行時(shí)發(fā)生的異常情況,下面這篇文章主要給大家介紹了關(guān)于JAVA中try-catch結(jié)構(gòu)之異常處理的使用方法,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-09-09
如何利用Spring把元素解析成BeanDefinition對(duì)象
這篇文章主要介紹了如何利用Spring把元素解析成BeanDefinition對(duì)象,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-08-08
SpringBoot 使用 Ehcache 作為緩存的操作方法
這篇文章主要介紹了SpringBoot 如何使用 Ehcache 作為緩存,我們通過添加 Ehcache 依賴、創(chuàng)建 Ehcache 配置文件并在 Spring Boot 應(yīng)用程序的配置文件中啟用 Ehcache 緩存,來配置 Ehcache 緩存,需要的朋友可以參考下2023-06-06
Jmeter?BlazeMeter實(shí)現(xiàn)web錄制過程
BlazeMeter是一款與Apache JMeter兼容的chrome插件,采用BlazeMeter可以方便的進(jìn)行流量錄制和腳本生成,作為接口測(cè)試腳本編寫的一個(gè)基礎(chǔ),這篇文章主要介紹了Jmeter?BlazeMeter實(shí)現(xiàn)web錄制,需要的朋友可以參考下2021-12-12
Java實(shí)現(xiàn)微信公眾號(hào)自定義菜單的創(chuàng)建方法示例
這篇文章主要介紹了Java實(shí)現(xiàn)微信公眾號(hào)自定義菜單的創(chuàng)建方法,結(jié)合實(shí)例形式分析了java創(chuàng)建微信公眾號(hào)自定義菜單的具體步驟、實(shí)現(xiàn)方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2019-10-10
Java與Mysql鎖相關(guān)知識(shí)總結(jié)
這篇文章主要介紹了Java與Mysql鎖相關(guān)知識(shí)總結(jié)的相關(guān)資料,需要的朋友可以參考下2023-04-04
區(qū)分Java中的ArrayList和LinkedList
這篇文章主要介紹了如何區(qū)分Java中ArrayList和LinkedList,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2020-06-06

