我在java中有一个自定义类,类似于
public class AddressesVO {
private Long addressId;
private String address;
public Long getAddressId() {
return addressId;
}
public void setAddressId(Long addressId) {
this.addressId = addressId;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
我的弹簧功能看起来像这样,
@RequestMapping(value="/searchAddress", method=RequestMethod.POST)
@ResponseBody
public String searchAddress(HttpServletRequest request, HttpServletResponse response, @RequestBody AddressesVO abc) {
System.out.println("This is the AddressesVO Object" +abc);
}
我正在对上述函数进行 ajax 调用并将 javascript 对象作为数据传递。
$.ajax({
type: "POST",
url: "searchAddress/",
data: objname,
success: function(){
alert('Form submitted');
alert(response);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert('failure'+response);
}
});
但我收到一条错误消息,提示客户端发送的请求在语法上不正确,并且它的运行失败
任何人都可以帮助我如何将 JS 对象发送到 spring 并将其作为自定义类接受。