Spring Boot

[Spring boot] @RequestMapping

라임오렌지원 2022. 10. 26. 21:48

@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

 

Spring MVC 예제 - @RequestMapping 어노테이션 예제

이번 포스팅은 이전에 작성한 직원 관리 예제를 가지고 설명을 하려고 합니다. [Java/Spring-framework] - Spring MVC 예제 - 직원 관리 프로그램 Spring MVC 예제 - 직원 관리 프로그램 이번 포스팅은 Spring MVC.

woolbro.tistory.com

 

728x90