본문 바로가기
[서버]/[SpringBoot Kotlin]

@RequestMapping을 사용하는 이유

by Hevton 2022. 12. 1.
반응형

 

Controller 클래스 내에서, 경로를 설정할 때

공통된 경로들을 지정하는 데에 간단한 방법으로 @RequestMapping을 사용할 수 있다.

 

@RestController
@RequestMapping(value = "/hello")
public class HelloController {

    @GetMapping()
    public String helloGet(...) {
        ...
    }

    @PostMapping()
    public String helloPost(...) {
        ...
    }

    @PutMapping()
    public String helloPut(...) {
        ...
    }

    @DeleteMapping()
    public String helloDelete(...) {
        ...
    }
}

/hello로 GET 요청을 보내면

helloGet()이 실행되고

 

/hello로 DELETE 요청을 보내면

helloDelete()가 실행된다

 

 

아래 블로그가 너어어어무 잘 정리되어 있어서

모든 분들이 보셨으면 좋겠다..

 

 

https://mungto.tistory.com/436

반응형

'[서버] > [SpringBoot Kotlin]' 카테고리의 다른 글

SpringBoot 프로젝트 생성하기  (0) 2022.12.03
JSON 구조  (0) 2022.12.01
Controller vs RestController 어노테이션 차이  (0) 2022.12.01
DAO vs DTO vs Entity  (0) 2022.11.24
Controller와 Service  (0) 2022.11.24