spring MVC 怎么获取前端传递的数组参数

2024-11-29 00:47:02
推荐回答(1个)
回答1:

可以这样写

主要是加了个@RequestParam(value = "titles[]")

Controller

1
2
3
4
5
6

@RequestMapping(value="/exportExcel", method = RequestMethod.POST)
@ResponseBody
public String exportExcel(@RequestParam(value = "titles[]") String[] titles){
System.out.println(titles);
return null;
}

jsp页面

1
2
3
4
5
6
7
8
9
10

var param = {titles:['col1','col2','col3']};
$.ajax({url:url, type:"post", data:param, async:false, dataType:"json", cache:false, error:function (data) {
rtnObj = data.responseText;
}, beforeSend:function (XMLHttpRequest) {
//ajaxStart();
}, complete:function (XMLHttpRequest, textStatus) {
//ajaxComplete();
}, success:function (data) {
rtnObj = data;
}});