스프링 요청방식 어노테이션 @RequestMapping / @GetMapping / @PostMapping

728x90

Request(응답)로는 get방식과 post 방식이 있다.

@RequestMapping 어노테이션을 사용하는 방법이다. 

method 파라미터에 RequestMethod.GET, POST로 응답 받을 수 있다. 

@RequestMapping(value="/test", method = RequestMethod.GET)
public String test() {
	return "test";
}
@RequestMapping(value="/test", method = RequestMethod.POST)
public String test() {
	return "test";
}

 

이 어노테이션을 간단하게 만들어주는 어노테이션이 있다.

 

@GetMapping 과 @PostMapping 이 있다. 

사용방법은 다음과 같다.

@GetMapping("/test")
pbulic String test() {
	return "test";
}
@PostMapping("/test")
pbulic String test() {
	return "test";
}

 

 

반응형

'Back-End > Spring(Boot)' 카테고리의 다른 글

객체로 파라미터 주입받기  (0) 2021.03.05
스프링 파라미터 추출  (0) 2021.03.05
spring mvc 5 pom.xml 버전관리  (0) 2021.03.04
스프링 통합 테스트  (0) 2020.12.26
thymeleaf 템플릿 엔진으로 view 띄우기  (0) 2020.12.26