使用@RequestParam接收前端传参


springboot项目,前端如果需要传多个参数,且后端没有专门QO来接收,后端可以使用@RequestParam接收参数;

前端ajax代码:

var data = {};
data.ids = "1,2,3";
data.sellerName = "XXX";
data.sellerBankNo = "XX行";
$.ajax({
    url: prefix + "/batchRemitSuccess",
    type: "post",
    dataType: "json",
    data: data,
    contentType : 'application/x-www-form-urlencoded',
    beforeSend: function () {
        $.modal.loading("正在处理中,请稍后...");
    },
    success: function (result) {
        console.log(result);
    }
})

注意: contentType : 'application/x-www-form-urlencoded',而不能用 contentType : 'application/json',否则后端接收到的数据为null;

后端:

@PostMapping("/batchRemitSuccess")
@ResponseBody
public AjaxResult batchRemitSuccess(@RequestParam("ids") String ids, @RequestParam("sellerName") String sellerName, @RequestParam("sellerBankNo") String sellerBankNo) {
    System.out.println(ids + "==" + sellerName + "==" + sellerBankNo);
    return null;
}

以上;


免责声明!

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



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