[ SpringMVC ] 往后台传集合(json)参数并在Controller层获取
作者:互联网
前端
/*数据封装在数组中*/
groupList.push({
selector: "select_"+(this.groupList.length),
member:["张倩","李晶晶"],
info:"负责根据专家组的建议和事件现场情况,迅速组织抢修力量、调用专用防护用品和专用工具进行抢修抢险。及时控制危险源,控制易燃、易爆。",
name:"抢修排险组",
groupId:-1,
add:true
});
/*post 请求方式:指定协议*/
var groupConfigVO = this.groupList;
$.ajax({
type:"POST",
url: globalHolder.request.savePlanGroupConfig,
async:false,
dataType:"json",
contentType:"application/json", // 指定这个协议很重要
data:JSON.stringify(groupConfigVO),
success:function(data) {
}
});
Controler层
集合内对象定义:
public class GroupConfigVO {
private Integer groupId;
private List<String> member;
private String info;
private String selector;
private String name;
private boolean add;
public GroupConfigVO() {
}
public GroupConfigVO(Integer groupId, List<String> member, String info, String selector, String name, boolean add) {
this.groupId = groupId;
this.member = member;
this.info = info;
this.selector = selector;
this.name = name;
this.add = add;
}
//对应属性的setter和getter
...
}
利用List获取集合参数
@ResponseBody
@RequestMapping(value="/savePlanGroupConfig",method= RequestMethod.POST)
public RespMapJson savePlanGroupConfig(@RequestBody List<GroupConfigVO> groupConfigVO) {
//todo
return new RespMapJson(ResultCode.SUCC.getValue());
}
备注:
定义的对象一定要和传入的参数名一致!
标签:String,SpringMVC,json,add,private,selector,Controller,groupId,name 来源: https://blog.51cto.com/u_15263565/2884877