1.页面端
(1)按钮
<a href="#" class="btn btn-danger btn_batchDelete">
<span class="glyphicon glyphicon-trash"></span> 批量删除
</a>
(2)scritp
/*多条删除*/
$(".btn_batchDelete").click(function () {
if($(".cb:checked").length<1){
$.messager.popup("选一个先!");
return;
}
$.messager.confirm('温馨提示:', '确定删除这些员工了嘛?',function () {
//获取所有被选中元素的data-id值
let ids=[];
$(".cb:checked").each(function (i,e) {
ids.push($(e).data("id"));
})
//ajax
$.get("/employee/deleteBatch.do",{ids:ids},handlerDMLResult);
});
});
2.后端controller
@GetMapping("/deleteBatch")
@RequiredPermission(name="员工批量删除",expression="employee:deleteBatch")
@ResponseBody
public ResultBean deleteBatch(Long[] ids){
try {
employeeService.delete(ids);
return ResultBean.success();
}catch (RuntimeException e){
e.printStackTrace();
return ResultBean.fail("删除失败");
}
}