Springmvc接收数组参数,必须添加@RequestParam注解
注解格式@RequestParam(value="前端参数名[]")
示例:
controller端的代码
@RequestMapping("/array")
public void getArray(@RequestParam(value="datas[]") String[] names) {
for(int i=0;i<names.length;i++) {
System.out.println(names[i]);
}
}
前台请求代码
var bearnames = ['熊大',"熊二"];
$.ajax({
type:'post',
url:'/FileUpload/flowerController/array',
data:{
//datas为前端参数名
datas:bearnames
},
cache : false,
success:function(){
alert('参数传递成功');
},error:function(){
alert('参数传递失败');
}
})