jsp页面
function jqchk(){ //jquery获取复选框值 var arr=[]; var chk_value =[]; var chk_value=$('input[name="test"]:checked'); if(chk_value.length==0){ alert("至少要选择一个删除项!") }else { alert(chk_value); $.each(chk_value,function () { arr.push($(this).val());//把多选框数组的value放入自己定义的里面 }) alert(arr); $.ajax({ type:"post", url:"/house/todelete.action",//需要用来处理ajax请求的action data:{//设置数据源 ids: arr.join(",") }, dataType:"json",//设置需要返回的数据类型 success:function(data){ var count = data.flag; if(count == 1) { alert("发送成功"); window.location.href="/house/toall.action" } else { alert("发送失败"); } }, error:function(){ alert("系统异常,请稍后重试!"); } }); } }
mapper里的sql
<delete id="deleteByIds" parameterType="String"> delete from t_house where id in(${id}) </delete>
controller里
@RequestMapping(value = "/todelete.action",method = RequestMethod.POST) @ResponseBody public Map<String,Object> todelete(String ids){ Map<String, Object> map = new HashMap<>(); System.out.println(ids+"--------------------------"); iHouseService.deleteByIds(ids); map.put("flag",1); return map; }