我有以下Person
包含另一个类的Car
类
public class Person {
private String name
private Car car;
... getter and setters
}
public class Car {
private String manufacturer;
... getter and setters
}
在 Javascript 中,我执行以下操作:
person = new Object();
person.name = "Bob";
person.car = new Object();
car = person.car;
car.manufacturer = "Mercedes";
$.ajax({
url: 'someurl.com',
type: 'POST',
data: person,
dataType: 'json',
...
complete: function() {
...
}
});
使用自动绑定功能时,出现以下错误:
功能:
public @ResponseBody Car validateCar( Car car, HttpServletRequest servletRequest){
...
}
错误:
org.springframework.beans.InvalidPropertyException: Invalid property 'car[manufacturer]' of bean class [com.example.Person]: Property referenced in indexed property path 'car[manufacturer]' is neither an array nor a List nor a Map; returned value was []
我必须做什么才能使映射工作?
顺便说一句:我的 POST 数据如下所示:
name: Bob
car[manufacturer]: Mercedes
字符串化为 JSON 它看起来如下(我对其进行了测试,但我没有对其进行字符串化)
{"name":"Bob",
"car": {
"manufacturer":"Mercedes"
}
}