spring 項目中的controller是不是不能直接接受對象類型的List為入參?為什么?找了很多相關文檔,都說不行,要不就傳一個vo類,vo類里面有list,要不就傳字符串,后臺解析字符串
spring boot 項目:
public class Tag {
int id;
String name;
此處省略了get,set
}
@RestController
public class HelloController {
@RequestMapping(value = "add", consumes = "application/json; charset=utf-8")
public String add(@RequestBody List<Tag> param) {
System.out.println("param:" + param);
return "成功";
}
}
commit(){
$.ajax({
type:"post",
url: 'add',
contentType:"application/json; charset=utf-8",
dataType:"json",
data:{
param:JSON.stringify([{id:1,name:'hello'},{id:2,name:'hello'}])
},
success:function(data){
console.log(data);
}
})
}
后臺報錯信息:
2018-01-29 13:52:57.856 WARN 3148 --- [nio-8088-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unrecognized token 'param': was expecting ('true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'param': was expecting ('true', 'false' or 'null')
添加回答
舉報
0/150
提交
取消