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; }
以上;
