首页 > 其他 > 详细

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

时间:2017-09-20 11:30:02      阅读:504      评论:0      收藏:0      [点我收藏+]
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;
        }
    });

 

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

原文:http://www.cnblogs.com/super-chao/p/7560317.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!