使用与不适用@RequestBody注解的区别

1.
如果使用@RequestBody接受页面参数:
public Map<String,Object> insertBudget(@ApiParam(required = true,name = "actBudgetCost",value = "预算")@RequestBody ActBudgetCost actBudgetCost, HttpServletRequest request){

}

那么前台页面ajax应该这样写:
$.ajax({
        url: '',
        type: "POST",
        data: JSON.stringify({
            "actiName":name
        }),
        dataType: "json",
        contentType: "application/json",
        async: false,
        success: function (result) {

        },
        error: function (xhr, ajaxOptions, thrownError) {
            //console.log(thrownError); //alert any HTTP error
            //alert("请求出错!");
            return false;
        }
    });

2.
如果不使用@RequestBody接受页面参数:
public Map<String, Object> regProduct(HttpServletRequest request,
                                           @ApiParam(name = "customerProAuditPO", value = "产品注册实体")CustomerProAuditVO customerProAuditVO
    ) {

}

那么前台页面ajax应该这样写:
var data = {
    customerName:customerName,
};
$.ajax({
        url:'',
        type: "POST",
        data: data, 
        //async: false,
        dataType:"json",
        success: function(result) {
            var json = result;

        },
        error: function (xhr, ajaxOptions, thrownError) {
            console.log(thrownError);
            return false;
        }
    });

 

posted @ 2017-09-20 10:55  super超人  阅读(9507)  评论(0编辑  收藏  举报