@RequestMapping
메소드 레벨, 클래스 레벨, HTTP Request Method 로 필요에 따라 사용할 수 있다.
보통 Controller에 걸어서 많이 사용한다.
- 메소드 레벨
@Controller
public class TestController{
@RequestMapping("/test/test1")
public class getTest(Model model){
return "test";
}
}
- 클래스 레벨
어노테이션의 공통적인 부분을 묶어서 선언하여 사용할 수 있다.
@Controller
@RequestMapping("/test/*")
public class TestController{
@RequestMapping
public class getTest(Model model){
return "test";
}
@RequestMapping("/add")
public class addTest(Model model){
return "testAdd";
}
}
- HTTP Request Method
동일한 URL에 요청 방법(Request Method)만 다르게 보냄
@Controller
@RequestMapping("/test/")
public class TestController{
@RequestMapping(method = RequestMethod.GET)
public class getTest(Model model){
return "test";
}
@RequestMapping(method = RequestMethod.POST)
public class addTest(Model model){
return "testAdd";
}
}
@RequestMapping 을 접하면서 정리해봤다..
참고사이트
https://woolbro.tistory.com/43
728x90