我試圖將JSON數據發佈到Spring Portlet控制器方法。 Modelattribute對象是嵌套的。這裏是JSON:JSON ajax POST到Spring Portlet控制器@ResourceMapping轉換問題
$(document).on({
change: function() {
...
...
formData = {
"name": "Demo",
"id": 724,
"periodId": 2015,
"orgId": 4,
"fieldGroupList": [{
"name": "instructions",
"label": "Instructions",
"fieldList": [{
"name": "INSTRUCTION",
"instructionList": [{
"instructionText": "All enabled fields are required for completion of this screen."
}],
"type": "INSTRUCTION"
}]
}]
};
阿賈克斯:
$.ajax({
async: "false",
global: "false",
url: validateURL,
type: "POST",
data: formData,
dataType: "json"
}).done(function(json){
console.log(json);
}).fail(function(jqXHR, textStatus, error) {
console.log("responseText: "+jqXHR.responseText);
});
控制器:
@ResourceMapping(value = "validateURL")
public void validate(@ModelAttribute(value = "formData") Measure measure,
BindingResult bindingResult, ResourceRequest request, ResourceResponse response, ModelMap model) throws Exception {
System.out.println("ab:::"+measure.getId());
}
型號:
public class Measure
{
private String name;
private List<MeasureFieldGroup> fieldGroupList = new ArrayList<MeasureFieldGroup>();
...
}
另外,如果JSON更改爲一切工作正常:
formData = {
"name": "Demo",
"id": 724,
"periodId": 2015,
"orgId": 4
};
錯誤控制器:
org.springframework.beans.InvalidPropertyException: Invalid property 'fieldGroupList[0][fieldList][0][instructionList][0][instructionText]' of bean class abc.measures.base.Measure]: Illegal attempt to get property 'fieldGroupList' threw exception; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property 'fieldGroupList[0][fieldList][0][instructionList][0][instructionText]' of bean class [abc.measures.base.Measure]: Property referenced in indexed property path 'fieldGroupList[0][fieldList][0][instructionList][0][instructionText]' is neither an array nor a List nor a Set nor a Map; returned value was [[email protected]]
我的問題是非常相似的 Post Nested Object to Spring MVC controller using JSON和 Spring Portlet Jquery Ajax post to Controller
但不能使用ResponseBody和RequestBody由於春季的Portlet。任何幫助將不勝感激。
感謝