@RequestMapping 애노테이션 속성
1. @RequestMapping
- URL과 Controller 메소드의 매핑을 설정하는 애노테이션이다
- URL 이외에도 다양한 속성을 지정할 수 있다
- URI 템플릿 기능을 이용하면 URL속의 값을 쉽게 얻어 올 수 있다
2. 속성
- 모든 속성은 배열을 사용해 여러 값을 설정할 수 있다
1) Value
- URL/customer
@RequestMapping
(value=
"/customer"
)
@RequestMapping
(
"/customer"
)
- 배열
1 2 | @RequestMapping ( "{/foo" , "/bar" }) @RequestMapping (value = { "/foo" , "/bar" }) |
- /foo와 /bar 양쪽 URL에 대응하는 메소드를 정의함
2) HTTP 메소드
- URL 만 설정시 어떤 HTTP메소드라도 받아들임
a. 한정 하고 싶을시 methd 설정
1 2 3 4 5 6 7 | //GET @RequestMapping (value = "/foo" , method= RequestMethod.GET) public String executeGetOnly(... //POST @RequestMapping (value= "/foo" , mehtod= RequestMethod.POST) public String executePostOnly(... |
b. static import를 클래스 처음에 정의하면 소스가 깔끔해짐
1 2 3 4 5 6 7 8 | import static org.springframework.web.bind.annotation.RequestMethod.*; @RequestMapping (value = "/foo" , method= GET) public String executeGetOnly(... //POST @RequestMapping (value= "/foo" , mehtod= POST) public String executePostOnly(... |
3) 요청 파라미터
- 같은 URL이라도 요청 파라미터가 action=new와 action = edit으로 구분할 수 있다
1 2 3 4 5 6 7 | //action = new @RequestMapping (value = "/foo" , params= "action=new" ) public String actNew(.... //action = edit @RequestMapping (value = "/foo" , params= "action=edit" ) public String actEdit(.... |
- action = new 접근 (http://~/컨텍스트 경로/foo?action=new..)
a. 요청 파라미터 키만 설정
1 | @RequestMapping (params = "new" ) |
- new = xxx 든 new = yyy 든지 new 라는 키의 요청 파라미터가 설정되어 있으면 실행
b. 이 요청 파라미터가 설정되지 않을 때
1 | @RequestMapping (params = "action != new" ) |
- 요청 파라미터 action의 값이 new가 아닐 때
c. 요청 파라미터 action 자체가 설정 되지 않은 때
1 | @RequestMapping (params = "!action" ) |
'Back-End > SpringFrame_1' 카테고리의 다른 글
[Spring] 클래스 레벨의 @RequestMapping (0) | 2016.08.24 |
---|---|
[Spring] @RequestMapping 애노테이션과 URL 템플릿 (0) | 2016.08.23 |
[Spring] PresentationLayer_Function of Spring (0) | 2016.08.16 |
[Spring] PresentationLayer_1 (0) | 2016.08.08 |
[Spring] BusinessLayer_2 (0) | 2016.08.07 |