我有以下控制器:「狀態」:415, 「錯誤」: 「不支持的媒體類型」
@PostMapping(value = {"/test/set_timeout"})
@ResponseBody
public void setAlertTimeout(@RequestBody Long timeout) {
從錯誤文本:
{"timestamp":1495560868392,"status":415,"error":"Unsupported Media Type","exception":"org.springframework.web.HttpMediaTypeNotSupportedException","message":"Content type 'multipart/form-data;boundary=----WebKitFormBoundary9IbVq5JAKxCYUs7P;charset=UTF-8' not supported","path":"/test/set_timeout"}
問題的原因以及如何發送請求正確?
P.S.
如果使用
public static class LongWrapper{
private long timeout;
public long getTimeout() {
return timeout;
}
public void setTimeout(long timeout) {
this.timeout = timeout;
}
}
,而不是龍,並通過JSON({"timeout":"2"}
) - 它的工作原理正確
請檢查此: https://stackoverflow.com/questions/43753357/http-status-415-post-json-data-to-spring-mvc-4-using-ajax-also-used-spring- sec?answertab = votes#tab-top – Zionz