來源於 https://blog.csdn.net/qq_40470612/article/details/104225419
1.用來處理Content-Type: 為 application/x-www-form-urlencoded編碼的內容。(Http協議中,如果不指定Content-Type,則默認傳遞的參數就是application/x-www-form-urlencoded類型) @RequestParam可以接受簡單類型的屬性,也可以接受對象類型。 2.用來處理 multipart/form-data (表單上傳的)
如何使用@RequestParam 接受JSON的字符串
前端代碼
const message = { "data": { "userInfo": "2804951212", "offerId": offerId, "action": "distribution", "categoryNav": categoryNav }, "gmtBorn": time, "msgId": time, "type": "PRODUCT_COLLECTION", "userInfo": "chrome" }; $.ajax({ contentType :'application/x-www-form-urlencoded', type:'post', url: baseUrl+'/ali-receive', data:"message="+JSON.stringify(message) });
@PostMapping("/ali-receive") public void aliReceive(@RequestParam("message") String message) { ReceiveLog receiveLog = JSON.parseObject(message, ReceiveLog.class); }
@RequestBody
一般用來處理 Content-Type: 為application/json