@RequestMapping(value = "/mapping-get-v1", method = RequestMethod.GET)
public String mappingGetV1() {
log.info("mappingGetV1");
return "ok";
}
위의 코드에 POST 요청을 하면 스프링 MVC는 405 상태코드(Method Not Allowed)를 반환
HTTP 메서드 매핑 축약
@GetMapping(value = "/mapping-get-v2")
public String mappingGetV2() {
log.info("mapping-get-v2");
return "ok";
}
PathVariable(경로 변수) 사용
@GetMapping("/mapping/{userId}")
public String mappingPath(@PathVariable("userId") String data) {
log.info("mappingPath userId={}", data);
return "ok";
}
@PathVariable의 이름과 파라미터의 이름이 같으면 생략할 수 있다
특정 파라미터 조건 매핑
@GetMapping(value = "/mapping-param", params = "mode=debug")
특정 헤더 조건 매핑
@GetMapping(value = "/mapping-param", headers = "mode=debug")
미디어 타입 조건 매핑 - HTTP 요청 Content-Type, consume
@GetMapping(value = "/mapping-param", consumes = "application/json")
미디어 타입 조건 매핑 - HTTP 요청 Accept, produce
@GetMapping(value = "/mapping-param", produces = "mode=debug")