【Jquery】ajax @requestBody

前端:
$.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 }

 

 
posted @ 2019-03-03 21:12  是谁扭曲了时空  阅读(2514)  评论(0编辑  收藏  举报