第一步:在dao层接口定义批量删除方
//批量删除
public int delMany(List<Integer> list);
第二步:在mapper映射文件中写sql语句
<delete id="delMany" >
delete from t_device where d_id in
<foreach collection="list" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
第三步:在service层接口定义批量删除方法
//批量删除
R delMany(List<Device> list);
第四步:实现service接口方法
public R delMany(List<Device> list) {
ArrayList<Integer> integers = new ArrayList<>();
for (Device device : list) {
integers.add(device.getD_id());
}
if (dao.delMany(integers)>0){
return R.ok();
}
return R.fail();
}
第五步:在controller层定义方法,与前段进行交互
@RequestMapping("delmany.do")
@ResponseBody
public R delMany(@RequestBody List<Device> list)
{
return service.delMany(list);
}
第五步:前段ajax
$.ajax({
type:'post',
url:"/api/device/delmany.do",
contentType:"application/json;charset=UTF-8",
data:JSON.stringify(data),
dataType:"json",
success:function (ret) {
}
})