java url中如何传递数组,springMVC框架controller类如何接收数组参数?
下面介绍一下URL中传递数组参数方法:
dd.php?titles[]=col1&titles[]=col2&titles[]=col3
或者使用ajax方式传递:
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; }});在springMVC中controller类接收数组参数的方法:
@RequestMapping(value="/save", method = RequestMethod.POST) @ResponseBody public String save(@RequestParam(value = "titles[]") String[] titles){ System.out.println(titles); return null; }