1
$.ajax({
cache:false,
type: 'POST',
url: "${saveDTO}",
data: mySubmitData, //a stringified json object, a form converted using toObject plugin
contentType: "application/json",
success: function(data) {
savedDialog.html(JSON.stringify(data) + "<br><br>"+mySubmitData);
}
});
和控制器是:轉換的json使用jquery POJO /春/傑克遜
public @ResponseBody MyDTO saveDTO(@Valid final MyDTO myDTO,BindingResult result, Model model){
System.out.println(myDTO.getMyField + " " + myDTO.getSecondField;
return new MyDTO();
}
輸出我在對話框中顯示得到這樣的:
{"myField":null,"secondField":null} //new empty dto converted and returned spring
{"myField":"RU","secondField":"13-02-12"} //submitted data, a form converted to json
雖然我SYS出去控制檯輸出顯示這兩個字段都是空的,JSON沒有約束!爲什麼? DTO本身只有兩個私人領域與適當的獲取/設置器
添加「MyDTO」的代碼 – beerbajay 2012-02-29 12:00:33