開發工具:ideamysql
springboot版本:2.2.6git
jdk版本:1.8ajax
這裏導入依賴就不作展現了(主要導入mybatis-plus與springboot依賴,看業務需求吧)redis
controller層代碼以下:spring
這裏主要是把字段修改了sql
/** * 批量刪除用戶信息 * 狀態爲1 :已刪除 * * @param state * @param userId * @return */ @PutMapping("delBatchUsers") @ApiOperation(value = "批量刪除用戶信息") public ResultFormat delBatchLink(Integer state, @RequestParam(value = "userId[]") Integer[] userId) { logger.info("state={}", state); Users users = new Users(); users.setState(1); boolean updateById = false; for (Integer integer : userId) { users.setUserId(integer); updateById = usersService.updateById(users); } if (updateById) { return ResultUtil.success(); } return ResultUtil.error(100, "修改失敗"); }
js代碼以下:springboot
table.render({ elem: '#valueTable' , url: '/users/list' , cols: [ [ {type: 'checkbox', fixed: 'left'} , {field: 'userId', title: 'ID', fixed: 'left'} , {field: 'userIp', title: '用戶IP',} , {field: 'userName', title: '用戶名',} , {field: 'email', title: '用戶郵箱',} , {field: 'registerTime', title: '註冊時間',} , {field: 'updateTime', title: '修改時間',} , {field: 'age', title: '年齡',} , {field: 'telephoneNumber', title: '手機號',} , {field: 'nickname', title: '用戶暱稱',} , { field: 'state', title: '狀態', width: 85, templet: function (data) { if (data.state == 0) { return '<div> <input type="checkbox" checked="" name="codeSwitch" lay-skin="switch" id="open" lay-filter="switchTest" switchId=' + data.userId + '' + ' lay-text="啓用|已禁用" value=' + data.state + '></div>'; } return '<div> <input type="checkbox" lay-skin="switch" name="codeSwitch" switchId=' + data.userId + ' lay-filter="switchTest"' + 'lay-text="啓用|已禁用" value=' + data.state + '></div>'; } } , {fixed: 'right', title: '操做', toolbar: '#barDemo'} ] ] , limit: 10 , limits: [10, 20, 25, 50, 100] , parseData: function (data) { //打印數據 console.log(data) } /** * 開啓分頁 */ , page: true , where: {state: 0} , id: 'linkListReload' });
var $ = layui.$, active = { /** * 批量刪除連接 * * */ closeBtn: function () { var $checkbox = $('table input[type="checkbox"][name="layTableCheckbox"]'); var $checked = $('table input[type="checkbox"][name="layTableCheckbox"]:checked'); if ($checkbox.is(":checked")) { var checkStatusId = table.checkStatus('linkListReload'), data = checkStatusId.data, userId = []; for (var i in data) { userId.push(data[i].userId) } layer.confirm('肯定要刪除' + data.length + '條數據麼?', {title: '系統信息'}, function (index) { var layerIndex = layer.load(2); $.ajax({ url: '/users/delBatchUsers', type: 'PUT', data: { state: 1, userId: userId }, success: function (res) { if (res.code == 200) { table.reload('linkListReload', {}); $.message({ message: res.msg, type: 'success', showClose: true }); } else { $.message({ message: res.msg, type: 'warning', showClose: true }); } }, error: function (data) { $.message({ message: '系統異常..', type: 'error', showClose: true }); }, complete: function () { layer.close(index); layer.close(layerIndex); } }) }) } else { $.message({ message: '請選中要刪除的數據', type: 'warning', showClose: true }); } }, }; $('.batchDel').on('click', function () { var type = $(this).data('type'); active[type] ? active[type].call(this) : ''; });
效果圖以下:mybatis
碼雲地址:https://gitee.com/ckfeng/springboot_mysql_redis.gitapp