반응형
spring boot로 백엔드, 뷰 부분을 thymleleaf를 사용해서 api로 통신하는 게시판을 만드는 중이었다.
자바스크립트로 fetch()를 통해 post 방식으로 요청하고 있었다.
그런데 swagger와 junit test를 수행 했을 때는 완벽했던 것이 전혀 말을 듣지 않았다.
먼저 그 이유는
@RequestBody 를 spring이 아닌 swagger에서 import 했기 때문이다.
엄청난 검색 끝에,, stack over flow에서 찾아냈다.. 설마 import 가 잘못 됐을 줄이야...
시도했던 방법들은
1. js의 stringify로 변환되기 전의 params에 ""붙이기 -> 이 방식은 전혀 아님..
2. dto 의 필드에 @JsonProperty 붙이기 -> java와 js에서의 다른 형식인 이름을 매칭해줌.
3. jackon data bind 의존성 추가하기
도움이 된 곳
https://stackoverflow.com/questions/38935912/requestbody-is-getting-null-values
@RequestBody is getting null values
I have created a simple REST service (POST). But when i call this service from postman @RequestBody is not receiving any values. import org.springframework.http.MediaType; import org.springframewo...
stackoverflow.com
반응형
'spring | spring boot > 오류 해결' 카테고리의 다른 글
springboot - spring security 기억할것 (내가..) (0) | 2022.04.13 |
---|---|
SpringBoot - security : localhost에서 리디렉션한 횟수가 너무 많습니다. (0) | 2022.03.31 |
SpringBoot h2 데이터베이스 연결 안됨, spring security영향때문.. (0) | 2022.02.25 |
spring security - Error creating bean with name 'springSecurityFilterChain' (0) | 2022.02.20 |
spring(?)-뷰 맵핑시 한글 깨짐 현상, javascript 연결, 약간의 vue문법문제 (0) | 2022.01.28 |
댓글