js:
先自定义一个数组,
var ids = [1,2];//数组里的值随便给一下,这里只能给正整数 $.ajax({ url:"../../areaController/deleteArea", type:"POST", data:{ids:ids}, dataType:"json", traditional:true,//这个是必须要的 success:function(data){ }, });
controller:
@ResponseBody @RequestMapping("/deleteArea") public Map<String,Object> deleteArea(HttpServletRequest request){ Map<String,Object> map = new HashMap<>(); String[] id = request.getParameterValues("ids");//接收数组 Integer num = iAreaService.deleteArea(id); map.put("msg",num > 0 ? "SUCCESS" : "ERROR"); return map; }
SQL:
<!-- 删除 forEach : 用来循环 collection : 用来指定循环的数据的类型 可以填的值有:array,list,map item : 循环中为每个循环的数据指定一个别名 index : 循环中循环的下标 open : 开始 close : 结束 separator : 数组中元素之间的分隔符 --> <update id="deleteArea"> update area set isdelete = 1 where id IN <foreach collection="array" index="index" item="item" open="(" separator="," close=")"> #{item} </foreach> </update>
@ResponseBody
@RequestMapping("/deleteArea")
public Map<String,Object> deleteArea(HttpServletRequest request){
Map<String,Object> map = new HashMap<>();
String[] id = request.getParameterValues("ids");
Integer num = iAreaService.deleteArea(id);
map.put("msg",num > 0 ? "SUCCESS" : "ERROR");
return map;
}