- AnnotationベースのSpring ControllerはSpringがサポートする様々なパラメータを使用することができる。
-
@Controllerの使用可能なパラメータリストは、以下のマニュアルで確認できる。
https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-controller/ann-methods/arguments.html@RestController public class RequestHeaderController { @RequestMapping("/headers") public String headers(HttpServletRequest request, HttpServletResponse response, HttpMethod httpMethod, Locale locale, // すべてのHTTPヘッダーをMultiValueMap形式で照会する。 // Mapと似ているが、1つのキーに複数の値を受け取ることができる。 @RequestHeader MultiValueMap<String, String> headerMap, // 특정 HTTP 헤더를 조회한다. @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"; } // http://localhost:8080/headers 요청 ...request=org.apache.catalina.connector.RequestFacade@29009f68 ...response=org.apache.catalina.connector.ResponseFacade@27c76438 ...httpMethod=GET ...locale=ko_KR ...headerMap={user-agent=[PostmanRuntime/7.33.0], accept=[*/*], postman-token=[ffa36d3b-4c1a-4f42-b5ad-181f504b3082], host=[localhost:8080], accept-encoding=[gzip, deflate, br], connection=[keep-alive]} ...header host=localhost:8080 ...myCookie=null }
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme