不考虑再添加一个封装类,
后台代码就只能这样,唯一的改变可以更改入参的位置,还有入参上的注解,和方法上的注解,前台应该怎么写?
@ResponseBody
@RequestMapping(value = "add", consumes = "application/json; charset=utf-8")
public String add(@RequestBody String content, @RequestBody List<Tag> param) {
前台:
$.ajax({
type:"post",
url: 'add',
contentType:"application/json; charset=utf-8",
dataType:"json",
data:JSON.stringify({
content:"nihaoahaha",
param:[{id:1,name:"hello"},{id:2,name:"hello"}]
}),
success:function(data){
console.log(data);
}
})
如果我只接收一个list是正常的:
后台代码:
@ResponseBody
@RequestMapping(value = "add", consumes = "application/json; charset=utf-8")
public String add(@RequestBody List<Tag> param) {
System.out.println("param:" + param);
return "成功";
}
前台代码:
$.ajax({
type:"post",
url: 'add',
contentType:"application/json; charset=utf-8",
dataType:"json",
data:JSON.stringify([{id:1,name:"hello"},{id:2,name:"hello"}]),
success:function(data){
console.log(data);
}
})
正常
至尊宝的传说
喵喔喔
相关分类