Error
[Spring] Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
지구
2020. 3. 20. 12:04
[Handler] Throwable Error!!! uri: {호출한 URI}, trace: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
개요 : 단순 form 에 데이터 넣고 submit 때린 것 밖에 없는데.. 왜 받질 못하니 😭
<form id="testForm" name="testForm" method="post" action="{호출할 URI}">
<input...>
<input...>
</form>
@PostMapping("/{호출할 URI}")
@ResponseBody
public Object myTestMethod(@RequestBody TestModel testModel) {
// 수행코드
}
원인 : 다른 POST 통신할 때와 동일하게 모델을 @RequestBody 로 받으려고했기 때문..
@RequestBody : body 에 있는 json 데이터를 파싱해줌
해결 : @ModelAttribute 로 모델을 받으니까 잘 된다..ㅠ_ㅠ
😓 머쓱머쓱.. 똑똑한 Spring.. 엉뚱한 Annotation 쓰지말고 잘 알고, 잘 맞게 Annotation 을 사용하자.
반응형