스프링 MVC 여러 종류의 요청매핑 사용하는 방법
2022.02.22
API매핑 API를 매핑하는 2가지 방식이다. 두 번째 방식은 첫 번째 방식의 축약형이다. (1) @RequestMapping("/hello", method = "RequestMethod.GET") 매핑할 경로와 HTTP메소드를 입력해주는 방식이다. @RequestMapping("/hello", method = "RequestMethod.GET") public String hello() { return "hello"; } @Controller어노테이션을 사용할 경우 return하는 이름의 html파일을 찾아서 리턴할 것이고 @RestController어노테이션을 사용한다면 return하는 문자열을 그대로 반환할 것이다. (2) @PostMapping("/hello") @RequestMapping에서 HT..