2017-12-21 2 views
-1

spring의 @requestbody 주석에 문제가 있습니다. 실제로 양식의 데이터를 복구하고 변환 할 수 없습니다.Spring @RequestBody가 작동하지 않습니다.

There was an unexpected error (type=Unsupported Media Type, status=415). 
Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported 

내가

여기

내 스프링 코드 봄 부팅 버전 1.5.8을 사용하고 있습니다 : 나는이 예외가 나는 @RequestBody없이 시도

@RequestMapping(value = "/insert",method = RequestMethod.POST,consumes = MediaType.APPLICATION_FORM_URLENCODED) 
public void createType(@RequestBody Type type) { 
    typeService.createType(type); 
} 

를, 그렇지 않습니다 너무 일한다.

<!DOCTYPE HTML> 
<html xmlns:th="http://www.thymeleaf.org"> 
<head> 
    <title>Getting Started: Handling Form Submission</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
</head> 
<body> 
    <div id="app"> 
    <h1>TEST FORM</h1> 
    <form action="#" method="post"> 
     <p>Type description: <input type="text" v-model="description"/></p> 
     <li v-for="some in someData"> {{ some }} </li> 
     <p><button v-on:click="addType()"> Send </button><input type="reset" value="Reset" /></p> 
    </form> 
    </div> 


    <script src="http://cdn.jsdelivr.net/vue/1.0.10/vue.min.js"></script> 
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script> 

     <script> 
     Vue.prototype.$http = axios; 
     new Vue({ 
      el:'#app', 
      data:{ 
       description:'', 
       someData:[] 
      }, 
      methods:{ 
       addType(){ 
        this.$http.post('/types/insert',{description:this.description}).then(response => { 
         this.someData:response.data; 
        }); 
       } 
      } 
     }); 
     </script> 
</body> 
</html> 

application/x-www-form-urlencoded를 사용한다

+0

[application/x-www-form-urlencoded 및 charset = "utf-8"?]의 가능한 복제본 (https://stackoverflow.com/questions/16819502/application-x-www-form-urlencoded-and) -charset-utf-8) – tkruse

+0

https://stackoverflow.com/questions/34782025/http-post-request-with-content-type-application-x-www-form-urlencoded-not-workin/38252762#을 참조하십시오. 38252762, https://stackoverflow.com/questions/33796218/content-type-application-x-www-form-urlencodedcharset-utf-8-not-supported-for – tkruse

+0

이 게시물을 이미 방문했지만 문제가 해결되지 않았습니다. 문제. – kasko

답변

0

당신의 클라이언트 유형 application/x-www-form-urlencoded;charset=UTF-8 통화를 ... 사전에 감사합니다 :

그리고 여기가 vuejs와 Axios의를 사용하여 내 HTML입니다. 그것이 작동하는 경우에도,

const config = { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }; 
this.$http.post(
    '/types/insert', 
    {description:this.description}).then(response => { 
        this.someData:response.data; 
       }, 
    config); 

어쩌면 당신은 또한

@RequestMapping(... @consumes = "application/x-www-form-urlencoded;charset=UTF-8") 

을 시도 할 수 있습니다하지만 그 나쁜 솔루션과 같습니다

어쩌면 당신은 당신의 HTML에서이 작업을 수행 할 수 있습니다.

+0

안녕하세요, 귀하의 답변을 이해할 수 없습니다. 어떻게해야합니까? – kasko

+0

저는 전문가가 아니지만 사용 된 컨텐츠 유형을 변경할 필요가 있습니다. https://github.com/axios/axios/issues/362 – tkruse

+0

감사합니다.하지만 이미이 토론을 방문했습니다. – kasko

관련 문제