How to pass an array in the Java URL, how does the SPRINGMVC Framework controller class receive array parameters?
Here's how to pass an array parameter in a URL:
Dd.do?titles[]=col1&titles[]=col2&titles[]=col3
or using Ajax to pass:
var
param = {titles:[
‘col1‘
,
‘col2‘
,
‘col3‘
]};
$.ajax({url:
"dd.php"
, 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;
}});
In Springmvc, the controller class receives array parameters in the method:
@RequestMapping
(value=
"/save"
, method = RequestMethod.POST)
@ResponseBody
public
String save(
@RequestParam
(value =
"titles[]"
) String[] titles){
System.out.println(titles);
return
null
;
}
Springmvc passing and receiving array parameters