在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ springboot @RequestBody 獲取不到content-type

springboot @RequestBody 獲取不到content-type="application/json"請(qǐng)求數(shù)據(jù)

我現(xiàn)在想獲取一個(gè)content-type=application/json的回調(diào)數(shù)據(jù),奇怪的是我使用@RequestBody獲取不到數(shù)據(jù),如下代碼所示 :

@Data
public class BaiduDocNofityResponse {
    private String messageId;
    private String messageBody;
    private String notification;
    private String server;

    private String subscriptionName;
    private String version;
    private String signature;
}

@PostMapping("/doc/notify")
public void notify(@RequestBody BaiduDocNofityResponse response){
    log.info("百度上傳文檔的回調(diào)通知:");
    log.info(response.toString());//**這里根本沒有打印出數(shù)據(jù)**

}

但是如果換成下面這段代碼就能獲取到:

@PostMapping("/doc/notify")
public void notify(HttpServletRequest request) throws IOException {
    log.info("request content-type=" + request.getContentType());
    log.info("百度上傳文檔的回調(diào)通知:" + request.toString());
    InputStream is = request.getInputStream();
    String val = StreamUtil.inputStream2String(is, "UTF-8");
    log.info(val);//**這里能打印出數(shù)據(jù)**
}

有誰知道是什么原因嗎?

回答
編輯回答
執(zhí)念

不是通過JSON/Body格式傳你的,你可以用@ModelAttribute替換@RequestBody,取Form/URL格式傳值。而且兩種方式對(duì)日期等特殊類型的format處理不太一樣。

2017年10月2日 12:47
編輯回答
安若晴

解決了,原因既然是log.info(response.toString());//這里的toString()不起作用,如果直接獲取如:response.messageBody是獲取到的,我真是醉了

2017年11月8日 00:38