====== SpringMVC Anntations ====== ===== @RequestMapping ===== * [[http://docs.spring.io/spring-framework/docs/4.0.x/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html|RequestMapping.java]] ==== 메소드 @RequestMapping 에 value 지정않았을 경우 ==== Controller 클래스의 ''@RequestMapping(value="/test/request")''에 이런식으로 지정하고, 메소드의 @RequestMapping을 빈 값으로 두면 이 메소드가 그 컨트롤러의 기본 핸들로러 지정된다. 문제는 이 경우 **매핑 되지 않는 모든 요청이 기본 핸들러로 다 들어온다**는 점이다. 원치 않는 리퀘스트를 받을 수 있으므로 @RequesMapping(**value=""**) 정도라도 지정해 줘야 명시적으로 "/test/request" 로 들어오는 요청만 받게 할 수 있다. ==== @RequestMapping params, headers, consumes, produces ==== * ''@RequestMapping(value="/url", params = {"download=true"})'' : ''/url?download=true'' 로 파라미터가 붙었을 경우에 매핑, ''download'' 파라미터가 없거나 값이 ''true''가 아니면 해당 컨트롤러는 호출되지 않음. * ''@RequestMapping(value = "/something", headers = {"content-type=text/*"})'' : ''content-type'' 헤더의 값이 ''text/*''로 매핑. ==== @PathVariable ==== * [[http://www.javabeat.net/pathvariable-template-patterns-spring-mvc/|@PathVariable - URI Template Patterns in Spring MVC]] * ''@PathVariable'' 사용시 ''@RequestParam''만 사용했을 때보다 성능이 많이 저하된다. ==== @RequestParam ==== * [[https://www.baeldung.com/spring-request-param|Spring @RequestParam Annotation]] * 다중 값 파라미터의 경우 ''ids=1,2,3'', ''ids=1&ids=2&ids=3'' 둘 다 작동한다. @GetMapping("/api/foos") @ResponseBody public String getFoos(@RequestParam List id) { return "IDs are " + id; } http://localhost:8080/api/foos?id=1,2,3 ---- IDs are [1,2,3] http://localhost:8080/api/foos?id=1&id=2 ---- IDs are [1,2]