只接收一个List作为入参的话不报错,
下方为代码:
前台:
$.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);
}
})
后台:
@ResponseBody
@RequestMapping(value = "add", consumes = "application/json; charset=utf-8")
public String add(@RequestBody List param) {
System.out.println("param:" + param);
return "成功";
}
前台控制台显示的数据格式为:
[{id: 1, name: "hello"}, {id: 2, name: "hello"}]
0:{id: 1, name: "hello"}
1:{id: 2, name: "hello"}
那如果持环开行打进对端架处参触架码我通会法时果我后台想接受一个字符串和一个list该怎么直分调浏器代,刚求的一学础过功互有解小久宗点差维含数如写呢,
后台代码改为:
@ResponseBody
@RequestMapping(value = "add", consumes = "application/json; charset=utf-8")
public String add(@RequestBody String content, @RequestBody List param) {
前台应该怎么写?