6. 스프링 MVC - 기본 기능


HTTP 요청 - 기본, 헤더 조회

package hello.springmvc.basic.request;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpMethod;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

@Slf4j //개발자는 편리하게 log라고 사용
@RestController
public class RequestHeaderController {

		@RequestMapping("/headers")
		public String headers(HttpServletRequest request,
		
		HttpServletResponse response,
		
		HttpMethod httpMethod, //Http 메서드 조회
		
		Locale locale, //Locale 정보를 조회
		
		@RequestHeader MultiValueMap<String, String> //map과 유사, 하나의 키에 여러 값 받을 수 있음
		headerMap, //모든 http헤더를 MultiValueMap 형식으로 조회
		
		@RequestHeader("host") String host, //특정 http 헤더를 조회
		
		@CookieValue(value = "myCookie", required = false) //특정 쿠키를 조회
		//required -> 필수 값 여부 / 기본값 -> defaultValue
		
		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 요청 파라미터 - 쿼리 파라미터, HTML Form (발표)