我试图通过jQuery AJAX将对象的数组发送到Spring控制器。
这是JavaScript代码:
var data = new Array();
$.each(products, function (i) {
var temp = {};
temp.orpid = products[i].orpid;
temp.orpah = $('#orpah' + products[i].orpid).is(':checked');
temp.orpad = $('#orpad' + products[i].orpid).val();
data.push(temp);
});
$.postJSON(url + 'save',
data,
function(response) {
if (response.isAuthenticated && response.isAuthorized) {
if (response.hasErrors) {
$('#routeForm').setErrors(response.errors);
hideWait();
}
}
else
redirectToLogin();
});
以下是发送到服务器的参数:
[{"orpid":10,"orpah":false,"orpad":""},{"orpid":11,"orpah":false,"orpad":""}]
控制器的方法具有以下定义:
@RequestMapping(value = "/save", method = RequestMethod.POST, headers = BaseController.AJAX_HEADER)
public ModelAndView save(@RequestBody HandlingOrderProductActionForm form, HttpServletResponse response) {...}
其中HandlingOrderProductActionForm为:
public class HandlingOrderProductActionForm extends BaseForm {
public class ActionForm {
private Boolean orpah;
private String orpad;
private Long orpid;
public ActionForm() { }
public void setOrpah(Boolean orpah) {
this.orpah = orpah;
}
public Boolean getOrpah() {
return orpah;
}
public void setOrpad(String orpad) {
this.orpad = orpad;
}
public String getOrpad() {
return orpad;
}
public void setOrpid(Long orpid) {
this.orpid = orpid;
}
public Long getOrpid() {
return orpid;
}
}
private List<ActionForm> actions;
/**
*
*/
public HandlingOrderProductActionForm() {
super();
}
public void setActions(List<ActionForm> actions) {
this.actions = actions;
}
public List<ActionForm> getActions() {
return actions;
} }
问题是服务器返回415错误:
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ().
有任何想法吗?
谢谢
最佳答案
问题已解决-只需将ActionForm移到单独的类上即可!