Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 인프런
- transaction
- 자바
- pointcut
- Thymeleaf
- 알고리즘
- 김영한
- Greedy
- Spring Boot
- 백준
- db
- Android
- springdatajpa
- 스프링 핵심 기능
- kotlin
- AOP
- jpa
- JPQL
- 스프링 핵심 원리
- Exception
- 그리디
- SpringBoot
- 스프링
- Proxy
- java
- Servlet
- QueryDSL
- http
- spring
- JDBC
Archives
- Today
- Total
개발자되기 프로젝트
HTTP 요청 - Header 조회 본문
1. Header조회
@Slf4j
@RestController
public class RequestHeaderController {
@RequestMapping("/headers")
public String headers(HttpServletRequest request,
HttpServletResponse response,
HttpMethod httpMethod,
Locale locale,
@RequestHeader MultiValueMap<String, String> headerMap,
@RequestHeader("host") String host,
@CookieValue(value = "myCookie", required = false) String cookie){
log.info("request={}", request);
log.info("response={}", response);
log.info("httpMethod={}", httpMethod);
log.info("locale={}", locale);
log.info("headerMap={}", headerMap);
log.info("header host={}", host);
log.info("myCookie={}", cookie);
return "ok";
}
}
- HttpServletRequest
- HttpServletResponse
- HttpMethod : HTTP 메서드를 조회한다. org.springframework.http.HttpMethod
- Locale : Locale 정보를 조회한다.(언어 정보, 우선순위 제일 높은 언어 표시)
- @RequestHeader MultiValueMap<String, String> headerMap
- 모든 HTTP 헤더를 MultiValueMap 형식으로 조회한다.
- @RequestHeader("host") String host
- 특정 HTTP 헤더를 조회한다.
- 속성
- 필수 값 여부: required
- 기본 값 속성: defaultValue
- @CookieValue(value = "myCookie", required = false) String cookie
- 특정 쿠키를 조회한다.
- 속성
- 필수 값 여부: required
- 기본 값: defaultValue
2. 참고 : MultiValueMap
- 하나의 key에 여러 value mapping
- HTTP header, HTTP 쿼리 파라미터와 같이 하나의 키에 여러 값을 받을 때 사용한다.
- keyA=value1&keyA=value2
- keyA로 꺼내면 배열이 반환됨. ㅋㅋ
MultiValueMap<String, String> map = new LinkedMultiValueMap();
map.add("keyA", "value1");
map.add("keyA", "value2");
//[value1,value2]
List<String> values = map.get("keyA");
3. @Conroller 의 사용 가능한 파라미터 목록
Web on Servlet Stack
Spring Web MVC is the original web framework built on the Servlet API and has been included in the Spring Framework from the very beginning. The formal name, “Spring Web MVC,” comes from the name of its source module (spring-webmvc), but it is more com
docs.spring.io
4. @Conroller 의 사용 가능한 응답 값 목록
Web on Servlet Stack
Spring Web MVC is the original web framework built on the Servlet API and has been included in the Spring Framework from the very beginning. The formal name, “Spring Web MVC,” comes from the name of its source module (spring-webmvc), but it is more com
docs.spring.io
5. GitHub : 210914 Get Header
GitHub - bsh6463/MVC2
Contribute to bsh6463/MVC2 development by creating an account on GitHub.
github.com
'인프런 > [인프런] 스프링 MVC 1' 카테고리의 다른 글
HTTP 요청 파라미터 - @RequestParam (0) | 2021.09.14 |
---|---|
HTTP 요청 파라미터 - 쿼리 파라미터, HTML, Form (0) | 2021.09.14 |
RequestMapping - API (0) | 2021.09.14 |
Request Mapping (0) | 2021.09.14 |
Logging기능 (0) | 2021.09.13 |
Comments