springMVC怎么获取从jsp传过来的集合类似List<User>
展开全部
1前台拼成 json对象
var buttons= new Array();
var obj=new Object();
obj.name="2342";
var ar= new Array();
var obj1=new Object();
obj1.name = "242342";
obj1.type = "asdfas.png";
var obj2=new Object();
obj2.name = "asd";
obj2.type = "asd.png";
ar.push(obj1);
ar.push(obj2);
obj.subButton=ar;
var obj3=new Object();
obj3.title="asf";
var ar1= new Array();
var obj4=new Object();
obj4.name = "242342";
obj4.type = "asdfas.png";
var obj5=new Object();
obj5.name = "asd";
obj5.type = "asd.png";
ar1.push(obj4);
ar1.push(obj5);
obj3.subButton=ar1;
buttons.push(obj);
buttons.push(obj3);
var ob = JSON.stringify(buttons);
var url = "/weixin/rest/button/create";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: url,
data: ob,
async:false,
success: function (data) {
},
error: function (err) {
alert("err:" + err);
}
});
2@RequestBody 注解接受
@RequestMapping(value="save/questions.action",method={RequestMethod.POST})
@ResponseBody
public String saveQuestions(@RequestBody Object questionlist)
}
3 解析questionlist
关键工具
JSONArray.fromObject(questionlist);
(Question) JSONObject.toBean(question,Question.class);
(JSONArray) jsonObject.get("options")
var buttons= new Array();
var obj=new Object();
obj.name="2342";
var ar= new Array();
var obj1=new Object();
obj1.name = "242342";
obj1.type = "asdfas.png";
var obj2=new Object();
obj2.name = "asd";
obj2.type = "asd.png";
ar.push(obj1);
ar.push(obj2);
obj.subButton=ar;
var obj3=new Object();
obj3.title="asf";
var ar1= new Array();
var obj4=new Object();
obj4.name = "242342";
obj4.type = "asdfas.png";
var obj5=new Object();
obj5.name = "asd";
obj5.type = "asd.png";
ar1.push(obj4);
ar1.push(obj5);
obj3.subButton=ar1;
buttons.push(obj);
buttons.push(obj3);
var ob = JSON.stringify(buttons);
var url = "/weixin/rest/button/create";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: url,
data: ob,
async:false,
success: function (data) {
},
error: function (err) {
alert("err:" + err);
}
});
2@RequestBody 注解接受
@RequestMapping(value="save/questions.action",method={RequestMethod.POST})
@ResponseBody
public String saveQuestions(@RequestBody Object questionlist)
}
3 解析questionlist
关键工具
JSONArray.fromObject(questionlist);
(Question) JSONObject.toBean(question,Question.class);
(JSONArray) jsonObject.get("options")
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询