我正在尝试使用jquery ajax将数据从javascript传递到spring控制器。
var inputParam = {
name: "xxx",
address: {
city: "chicago",
zip: "123456"
}
};
var jqxhr = $.ajax({
url: "/myurl"+ $.param(inputparam),
type: "GET",
dataType: "html"
});
控制器
@RequestMapping(value = "/myurl", method = RequestMethod.GET)
public String getMyPage( @ModelAttribute InputParams inputParam,HttpServletRequest request, Model model ) throws Exception{
//my code
}
pojo
class InputParams
{
private String name;
private Address address;
//getter setter
}
class Address
{
private String city;
private String zip;
//getter setter
}
但这无法正常工作,并且出现错误
org.springframework.beans.InvalidPropertyException:Bean类[InputParams]的无效属性“ address [city]”:在索引属性路径“ address [city]”中引用的属性既不是数组也不是List也不是Map;返回值是[城市]