Spring MVC Controller 接收ajax的数组参数说明
https://blog.csdn.net/u012527870/article/details/72469572
/** * Created by xiongyu on 2017/5/12. */ $(function () { $("#deleteSelect").click(function () { .......//省略部分代码 var res = $.ajax({ url: "/SpringMybatis/user/deleteBySelective", data: {data: chk_value}, // traditional: true, 这里的取值后面说明 success: function () { console.log(res.responseText) loadData(); }, error: function () { console.log(res.responseText) } }) }); });
traditional默认是false,如果是false,则传递的参数为: data[]:1 ...... 这里设置为true,使传递参数变成: data:1 ......
若传递的数据格式是data[]:1,则RequestParam的value是data[],若传递的数据格式是data:1,则RequestParam的value是data,后面既可以用List接收,也可以用数组接收.
以traditional默认值时为例,controller代码为:
@RequestMapping(value = "deleteBySelective", produces = "text/html;charset=UTF-8;") @ResponseBody public String deleteBySelective(HttpServletRequest request, Model model,@RequestParam(value = "data[]")String[] data) { System.out.println("request now is here"); System.out.println(Arrays.asList(data)); userService.deleteBySelective(Arrays.asList(data)); return "whatever you like"; }
相关推荐
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
TONIYH 2020-07-22
时光如瑾雨微凉 2020-07-19
83510998 2020-07-18
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05
坚持着执着 2020-07-05