1.这是页面上的批量删除标签
<div class="button-border"><button id="remove" class="button">批量删除</button></div>
2.页面上获取$("#mytab").bootstrapTable('getSelections');的选中框!
// 删除按钮事件
$("#remove").on("click", function() {
if (!confirm("是否确认删除?"))
return;
var rows = $("#mytab").bootstrapTable('getSelections');// 获得要删除的数据
if (rows.length == 0) {// rows 主要是为了判断是否选中,下面的else内容才是主要
alert("请先选择要删除的记录!");
return;
} else {
var ids = new Array();// 声明一个数组
$(rows).each(function() {// 通过获得别选中的来进行遍历
ids.push(this.id);// cid为获得到的整条数据中的一列
});
deleteMs(ids)
}
})
function deleteMs(ids) {
$.ajax({
url : "${pageContext.request.contextPath }/deleteall.action",
data : "ids=" + ids,
type : "post",
dataType : "json",
success : function(data) {
alert(data.msg);
$('#mytab').bootstrapTable('refresh', {
url : '${pageContext.request.contextPath }/zhiye/GetList.action'
});
}
});
}
3。传递ids到controller中可以是for循环操作删除,也可以是在SQL中批量删除
//批量删除
@SuppressWarnings("null")
@ResponseBody
@RequestMapping(value="/deleteall",method=RequestMethod.POST)
public Result<JSONObject> deleteall(Model md,@RequestParam("ids")String ids,ZhiYe zhiye,HttpServletResponse response){
response.setHeader( "Access-Control-Allow-Origin", "*");
JSONObject json = new JSONObject();
System.out.println("ids获取的ids 的集合:======================="+ids);
String[] Ids = ids.split(",");
for (String string : Ids) {
zhiye.setId(Integer.parseInt(string));
zs.delete(zhiye);
}
return new Result<JSONObject>(json, "msg", "200");
}
}