| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
- 상호 인증
- 바이트 절삭
- mTLS
- WildFly
- Graphql Client
- 데이터 압축
- java
- Socket is closed
- mapstruct
- Request Body 여러 번 사용
- HandlerMethodArgumentResolver
- Srping MVC
- Java Singleton
- Jndi DataSource
- requestheaderdto
- tomcat jndi
- Java Rest
- Open Close Principal
- AfterMapping
- Tomcat DBCP
- try - with - resources
- Unchecked Exception
- Java Graphql
- 이중정렬
- graphql
- NoUniqueBeanDefinitionException
- 개방 폐쇄 원칙
- Reading HttpServletRequest Multiple Times
- Checked Exception
- Sub Bytes
- Today
- Total
Developer Sang Guy
[Spring] RequestMapping 기능 (produces, consumes ) 본문
produces : 매개 변수를 따로 설정하지 않는 경우 요청 헤더 중 Accept 값과 일치해야 합니다.
일치하지 않는 경우 [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html#produces--
레퍼런스에는 내용 없긴한데 테스트 해보니까 produces 값 따라 Response Content-Type 정해집니다.
produces = "text/plain"
|
1
2
3
4
5
6
|
@RequestMapping(value = "/home", method = RequestMethod.POST, produces = "text/plain")
@ResponseBody
public ResponseEntity<String> postHome(@RequestBody String body) throws Exception {
return new ResponseEntity<String>(body, HttpStatus.OK);
}
|
cs |

produces = "application/x-www-form-urlencoded"
|
1
2
3
4
5
6
|
@RequestMapping(value = "/home", method = RequestMethod.POST, produces = "application/x-www-form-urlencoded")
@ResponseBody
public ResponseEntity<String> postHome(@RequestBody String body) throws Exception {
return new ResponseEntity<String>(body, HttpStatus.OK);
}
|
cs |

consumes : 요청 헤더 중 Content-Type 값과 일치해야 합니다.
일치하지 않는 경우 [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'text/plain' not supported]
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html#consumes--
Accept : 클라이언트가 이해 가능한 컨텐츠 타입이 무엇인지 알려주는 용도로 사용 된다고 합니다.
예를들어 요청 해더 중 Accept의 값이 존재 한다면 서버는 해당 MIME 타입으로 Response를 주어야 함.
https://developer.mozilla.org/ko/docs/Web/HTTP/Headers/Accept
Content-Type : 응답 내에 있는 Content-Type은 클라이언트에게 반환 된 컨텐츠 유형이 실제로 무엇인지를 알려줍니다.
요청 내에 있는 Content-Type은 클라이언트가 서버에게 어떤 유형의 데이터가 실제로 전송됐는지를 알려줍니다.
https://developer.mozilla.org/ko/docs/Web/HTTP/Headers/Content-Type
'Spring' 카테고리의 다른 글
| RequestHeader를 Handler 매개 변수로 바인딩(HandlerMethodArgumentResolver) (0) | 2024.05.28 |
|---|---|
| HttpServletRequest Body 여러 번 읽기 (0) | 2022.12.28 |
| [Spring Boot] DB 연결 (0) | 2022.09.28 |
| [Spring] Aop, Logback 활용 (0) | 2022.04.28 |
| 스프링 WebMvcConfigurer (0) | 2021.08.08 |