@RequestMapping
- 참고 포스팅
- 들어온 요청을 특정 메소드와 매핑하기 위해 사용한다.
- value는 요청받을 url을 설정하게 된다.
- method는 어떤 요청으로 받을지 정의하게 된다.(GET, POST, PUT, DELETE 등)
- 예시 1은 예시 2로 바꾸어 간편하게 작성할 수 있다.
- 예시 1)
@RestController
public class HelloController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String helloGet(...) {
...
}
@RequestMapping(value = "/hello", method = RequestMethod.POST)
public String helloPost(...) {
...
}
@RequestMapping(value = "/hello", method = RequestMethod.PUT)
public String helloPut(...) {
...
}
@RequestMapping(value = "/hello", method = RequestMethod.DELETE)
public String helloDelete(...) {
...
}
}
@RestController
@RequestMapping(value = "/hello")
public class HelloController {
@GetMapping()
public String helloGet(...) {
...
}
@PostMapping()
public String helloPost(...) {
...
}
@PutMapping()
public String helloPut(...) {
...
}
@DeleteMapping()
public String helloDelete(...) {
...
}
}