jsp页面:
$("#out").click(function () {
var arr=[];//定义一个数组
var arr2=$(":checked");//获取多选框的数组
$.each(arr2,function () {
arr.push($(this).val());//把多选框数组的value放入自己定义的里面
})
alert(arr)
$.ajax({
url : "StockController/outBound.action",//发送到这
type : "GET",
data : {"ids" : arr.join(",")
},
dataType : "text", //如果后台返回的是字符串这要写上text 如果返回对象或者集合 写json
success : function(data){
alert(data);
if(data=="ok"){
alert("出库成功")
}
else{
alert("出货失败");
}
},
error : function(){
alert("bbbb");
}
});
Controller页面:
@RequestMapping(value = "outBound",method = RequestMethod.GET)
@ResponseBody
public String outBound(String ids){
System.out.println("进来了");
String[] split = ids.split(",");//因为传过来的ids以(1,2,3...)这种形式 所以要分割
for (String s:split
) {
int i =Integer.parseInt(s);
stockService.outBound(i);//每次都走这个方法
}
System.out.println("走完了");
return "ok";
}