애노테이션 기반의 스프링 컨트롤러는 다양한 파라미터를 지원한다. 간단한 예제 코드를 통해
HTTP 헤더 정보를 조회하는 방법을 알아 볼 것이다.
@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";
}
}
위의 코드를 통해 다양한 헤더를 조회하는 방법을 알 수 있다.
필요할 때 위 링크의 공식 문서를 활용하는것이 유용할 것 같다.
'Develop > Spring' 카테고리의 다른 글
| [MVC] http 응답 (0) | 2025.12.02 |
|---|---|
| [MVC] Http 요청 파라미터 (0) | 2025.12.02 |
| [jsp] 회원관리웹애플리케이션 (0) | 2025.12.01 |
| [Servlet] 회원관리웹애플리케이션 (0) | 2025.12.01 |
| [Servlet] HttpServletResponse (0) | 2025.12.01 |