使用與不適用@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