前端:
$.ajax({
type: "POST",
contentType: "application/json;charset=UTF-8",
url: REQUEST_URL.SAVE_ITEM_DETAILS,
async: false,
data: JSON.stringify(itemDetails.itemDetailList), //JSON对象需要转成JSON字符串 eg '{"id":"1","name":"猪八戒"}'
success: function (retResult) {
alert(retResult.retMsg);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("保存失败!");
}
});
后台:
@ResponseBody
@RequestMapping("/saveItemDetails")
public RetResult saveItemDetails(@RequestBody ItemDetail[] itemDetailList){
//ItemDetail中的属性不能少与JSON的属性,按照JSON属性映射赋值转换 (eg: private String id;private String name; 比如少了name属性,则接受不到)
//todo save
}