使用@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