Jquery 对象未从AJAX绑定到Spring控制器
我正在尝试使用jQueryAjax将数据从javascript传递到spring控制器Jquery 对象未从AJAX绑定到Spring控制器,jquery,ajax,spring-mvc,spring-boot,Jquery,Ajax,Spring Mvc,Spring Boot,我正在尝试使用jQueryAjax将数据从javascript传递到spring控制器 var inputParam = { name: "xxx", address: { city: "chicago", zip: "123456" } }; var jqxhr = $.ajax({ url: "/myurl"+ $.param(inputparam), type: "GET", dataType: "html" });
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]”中引用的属性既不是数组,也不是列表,也不是映射;返回值为[城市]
$.param(inputparam)
不创建与内容类型:'application/json'兼容的数据,
您不需要对发送的对象调用$.param
。如果您删除contentType:'application/json'
jQuery将为您将其编码为form urlencoded
,那么这应该是什么内容类型?@RoryMcCrossan我不明白您的意思。删除contenttype或删除$。参数同时删除这两个。。。。