使用@RequestParam接收前端传参
springboot项目,前端如果需要传多个参数,且后端没有专门QO来接收,后端可以使用@RequestParam接收参数;
前端ajax代码:
var data = {}; data.ids = "1,2,3"; data.sellerName = "XXX"; data.sellerBankNo = "XX行"; data.ids = "1,2,3"; $.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; }
以上;