layui+ssm實(shí)現(xiàn)數(shù)據(jù)批量刪除功能
layui+ssm實(shí)現(xiàn)數(shù)據(jù)的批量刪除
//數(shù)據(jù)表格 table.render({ id: 'adminList', elem: '#adminList', url: ctx + "/admin/getAdminList", //數(shù)據(jù)接口 cellMinWidth: 80, even: true, toolbar: '#toolbarDemo',//頭部工具欄 limit: 10,//每頁(yè)條數(shù) limits: [10, 20, 30, 40], defaultToolbar: ['filter', 'exports', 'print'], cols: [[ //表頭 {type: 'checkbox', fixed: 'left'}, {type: 'numbers', title: '序號(hào)', width: 80},//序號(hào)列 // {field: 'id', title: '編號(hào)', align: 'center', width: 80}, {field: 'username', title: '姓名', align: 'center'}, {field: 'phone', title: '電話', align: 'center'}, { field: 'gender', title: '性別', align: "center", templet: function (d) { if (d.gender == '2') { return '<button class="layui-btn layui-bg-orange layui-btn-xs ">女</button>'; } else if (d.gender == '1') { return '<button class="layui-btn layui-bg-cyan layui-btn-xs layui-btn-normal">男</button>'; } else if (d.gender == '') { return '<button class="layui-btn layui-bg-red layui-btn-xs layui-btn-normal">未知</button>'; } else { return ''; } } }, {field: 'roleName', title: '賬戶類型', align: 'center'}, ], page: true, loading: true }); /* * 監(jiān)聽頭部工具欄 * */ table.on('toolbar(adminList)', function (obj) { var phone = $("#phone").val(); //獲取前端頁(yè)面?zhèn)鬟^(guò)來(lái)的當(dāng)前登錄人的手機(jī)號(hào) var id = obj.config.id;//獲取當(dāng)前操作的id var checkStatus = table.checkStatus(id); var checkData = checkStatus.data; // 獲取選中的數(shù)據(jù) switch (obj.event) { case 'deleteBatch': if (checkData.length === 0) { layer.msg('請(qǐng)選擇一行數(shù)據(jù)再進(jìn)行操作!'); } else if (checkData.some(item => item.phone === phone)) { layer.msg("不允許刪除當(dāng)前賬戶!", {icon: 5}); } else if (checkData.some(item => item.roleName === "超級(jí)管理員")) { layer.msg("此賬戶你沒(méi)有權(quán)限操作!"); } else { layer.confirm('確定刪除所選賬戶嗎?', function (index) { $.ajax({ url: ctx + "/admin/deleteBatch", type: "POST", data: JSON.stringify({ids: checkData}), contentType: "application/json", success: function (d) { if (d.code === 0) { layer.msg(d.msg, {icon: 1}); table.reload('adminList', {}); } else { layer.msg("失??!", {icon: 5}); } }, error: function (jqXHR, textStatus, errorThrown) { layer.msg("獲取數(shù)據(jù)失??! 先檢查sql 及 Tomcat Localhost Log 的輸出"); } }); layer.close(index); }); } break; } });
controller
/* * 批量刪除 * */ // 定義一個(gè)名為deleteBatch的方法,用于處理批量刪除請(qǐng)求 @RequestMapping("/deleteBatch") @ResponseBody public ResultUtil deleteBatch(@RequestBody Map<String, Object> params, HttpSession session) { try { // 從請(qǐng)求參數(shù)中獲取要?jiǎng)h除的賬戶ID列表 List<Integer> ids = (List<Integer>) params.get("ids"); System.out.println(ids); // 調(diào)用adminService的deleteByIds方法,根據(jù)ID列表批量刪除賬戶 adminService.deleteByIds(ids); // 返回成功結(jié)果 return ResultUtil.ok("批量刪除賬戶成功"); } catch (Exception e) { // 如果發(fā)生異常,打印異常堆棧信息 e.printStackTrace(); // 返回錯(cuò)誤結(jié)果,狀態(tài)碼為500,提示信息為"sql問(wèn)題" return new ResultUtil(500, "sql問(wèn)題"); } }
service void deleteByIds(List<Integer> ids); serviceimpl: @Override public void deleteByIds(List<Integer> ids) { adminDao.deleteByIDS(ids); } dao: void deleteByIDS( List<Integer> ids);
mapper.xml
<delete id="deleteByIDS" parameterType="java.util.List"> DELETE FROM tb_admin WHERE id IN <foreach collection="list" open="(" close=")" separator="," item="param"> #{param.id} </foreach> </delete>
到此這篇關(guān)于layui+ssm實(shí)現(xiàn)數(shù)據(jù)批量刪除的文章就介紹到這了,更多相關(guān)layui ssm批量刪除內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
javascript實(shí)現(xiàn)隨機(jī)顯示星星特效
這篇文章主要介紹了javascript實(shí)現(xiàn)隨機(jī)顯示星星特效的相關(guān)資料,以一個(gè)完整實(shí)例形式較為詳細(xì)的分析了js實(shí)現(xiàn)隨機(jī)顯示星星特效的實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-01-01uniapp 如何設(shè)置 tabbar 的 midButton 按鈕
在UniApp開發(fā)中,設(shè)置TabBar的midButton按鈕可以增加用戶交互的便利性,本文介紹了在App.vue中監(jiān)聽事件的方法,并提供了官方文檔鏈接作為參考,通過(guò)這種方式可以實(shí)現(xiàn)TabBar中的特殊按鈕功能,提升應(yīng)用的用戶體驗(yàn)2024-10-10固定背景實(shí)現(xiàn)的背景滾動(dòng)特效示例分享
固定背景滾動(dòng)特效,使用background-attachment: fixed和導(dǎo)航菜單,頁(yè)面會(huì)非常平滑的滾動(dòng),感興趣的朋友可以參考下哈希望對(duì)你有所幫助2013-05-05解決layui table表單提示數(shù)據(jù)接口請(qǐng)求異常的問(wèn)題
今天小編就為大家分享一篇解決layui table表單提示數(shù)據(jù)接口請(qǐng)求異常的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09原生js獲取寬高與jquery獲取寬高的方法關(guān)系對(duì)比
這篇文章主要介紹了原生js獲取寬高與jquery獲取寬高的方法關(guān)系對(duì)比,需要的朋友可以參考下2014-04-04