測試時遇到的問題——關於spring

"exception": "org.springframework.web.HttpMediaTypeNotSupportedException",

"message": "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported",web


發起請求後返回以上錯誤信息。spring

網上查詢答案主要有如下幾種:json

    1. bean類的getter和setter方法出錯
springboot

    2. springmvc配置文件中沒加驅動 <mvc:annotation-driven/>     
mvc

    3. jar包的版本太低。。app

經排查:ide

    1. getter和setter都自動生成,沒有錯誤。
post

    2. 使用的是springboot,沒有spirngmvc的配置文件
url

    3. pom文件內添加的依賴。。版本沒有過低的。。
idea


最後發現是controller類中的該方法參數前面使用了註解@RequestBody。就是隻接受json的參數。。

可是我在postman裏面設置了以後仍是出現415錯誤。。而idea的控制檯卻是沒有異常輸出。

最後換了一個註解。@ModelAttribute。解決了。。。

相關文章
相關標籤/搜索