我認爲@RequestBody
試圖通過屬性名稱註釋之後將請求params
映射到對象。Spring MVC how @RequestBody如何工作
但是,如果我有:
@RequestMapping(value = "/form", method = RequestMethod.GET)
public @ResponseBody Person formGet(@RequestBody Person p,ModelMap model) {
return p;
}
請求:
http://localhost:8080/proj/home/form?id=2&name=asd
返回415
當我改變@RequestBody Person p
與@RequestParam Map<String, String> params
它的確定:
@RequestMapping(value = "/form", method = RequestMethod.GET)
public @ResponseBody Person formGet(@RequestParam Map<String, String> params) {
return new Person();
}
Person類:
public class Person{
private long id;
private String name;
public Person() {
}
public Person(long id, String name) {
super();
this.id = id;
this.name = name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
春vresion 3.2.3.RELEASE
我有什麼錯?
您是否嘗試添加一個默認構造函數到'Person'? – jbx
剛試過,沒有幫助。謝謝。 –