使用与不适用@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;
        }
    });

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM