ssm+layui实现批量删除layui复选框在点击换页选择的数据会重置这个问题暂时未解决
第⼀种⽅法:
//删除多⾏
//删除多⾏操作
@RequestMapping("/deleteAll")
@ResponseBody
public int  deleteAll(@RequestBody String ids)throws IOException {
System.out.println("ids:"+ids);
String replaceAll = place("[","").replace("]","");
System.out.println("我是replaceAll:"+replaceAll);
int  t =this.impl.deleteAll(replaceAll);
System.out.println("t是多少:"+t);
return t;
}
<delete id="deleteAll" parameterType="String">
delete from tb_student
where id in (${value})
</delete>
jsp页⾯部分代码
//头⼯具栏事件 。。。。。。
<('toolbar(test)',function (obj) {
/
/获取所有选中⾏。
var checkStatus =table.fig.id);
switch (obj.event) {
case 'getCheckData':
var data =checkStatus.data;
layer.alert(JSON.stringify(data));
break;
case 'delAll':
var data =checkStatus.data;
var arr =layui.$.map(data,function(d){return d.id;}); console.log("第⼀次输出:"+arr);
/
/  delAll(arr);
$.ajax({
type:'post',
url:"<%=basePath%>/student/deleteAll",
dataType:'json',
contentType:"application/json; charset=utf-8", data:JSON.stringify(arr),
//              请求成功的回调
success:function (data) { if (data >0) {
layer.msg("数据删除成功!", {
icon:1,
time:500,
});
}
}
})
layer.close(index);
});
break;
第⼆种⽅法
后端代码
@RequestMapping("/deleteCars")
@ResponseBody
public int deleteCars(@RequestBody String ids) { //ids=="0001,0203141da,31203123"
System.out.println("传⼊的ids:" + ids);
//  String str=  "";
//  String str2 = place("")
String str = place("\"","");
System.out.println("str:" + str);
String[] id = str.split(",");
System.out.println("id:" + id);
/
/String str = place("\","");
//数组转换为list
//String[] strs = {"1","3","12","33"};
//List sList = Arrays.asList(strs);
List newIds = Arrays.asList(id);
System.out.println("newIds:" + newIds);
List idsList =new ArrayList();
public Object transform(Object o) {
return Integer.String());
}
}, idsList);
Collections.sort(idsList);
System.out.println("idsList:" + idsList);
int result =service.deleteCars(idsList);
return result;
}
}
commons-collections commons-collections  3.2.1
这⾥有包需要导⼊
<delete id="deleteCars" parameterType="java.util.List">
delete from freightcar
where  id in
<foreach collection="ids" item="id" open="(" close=")" separator=","> #{id}批量更新sql语句
</foreach>
</delete>
jsp部分页⾯
//删除多⾏数据
function deleteRows(Object){
$.ajax({
type:'post',
url:"<%=basePath%>/car/deleteCars",
dataType:'json',
contentType:"application/json;charset=utf-8",
data:JSON.stringify(Object),
success:function(data){
if (data >0) {
layer.msg("您已经成功删除记录!", {
icon:1,
time:1300,
end:function () {
// load('totaldata');
}
});
}
}
});
}
//头⼯具栏事件 test是lay-filter中的test toolbar: '#toolbarDemo' //开启头部⼯具栏,并为其绑定左侧模板('toolbar(test)',function(obj){
var checkStatus =table.fig.id);
switch(obj.event){
case 'getCheckData':
var data =checkStatus.data;
layer.alert(JSON.stringify(data));
break;
case 'getCheckLength':