Notice
Recent Posts
Recent Comments
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

충분히 쌓여가는

컨트롤러 살펴보기, @RestController 본문

Spring/Spring Boot

컨트롤러 살펴보기, @RestController

빌드이너프 2023. 12. 19. 20:20
@RestController
public class TestController {
    @GetMapping("/test")
    public String test() {
        return "Hello world!";
    }
}

 

@RestController

라우터 역할을 하는 애너테이션

라우터: HTTP 요청과 메서드를 연결하는 장치

@RestController 애너테이션이 있어야 클라이언트 요청에 맞는 메서드를 실행할 수 있다

 

위 코드의 경우 /test라는 GET 요청이 왔을 때, test() 메서드를 실행하도록 구성한 것

 

@RestController과 @Component 같은 취급?

@RestController의 구성으로 @Controller과 @ResponseBody 애너테이션 존재

즉, @Contorller 애너테이션과 @ResponseBody 애너테이션이 합쳐진 결과물이 @RestController이다

 

@Controller 애너테이션의 구현 파일인 Controller.java에 보면 @Component 애너테이션이 존재

=> @Controller 애터네이션이 @ComponentScan을 통해 빈으로 등록되는 이유

 

@Configuration, @Repository, @Service 애너테이션 모두 @Component 애너테이션을 가지고 있음

'Spring > Spring Boot' 카테고리의 다른 글

스프링 부트 프로젝트 디렉터리 구성  (0) 2023.12.19
스프링 부트 3 구조  (0) 2023.12.19
@SpringBootApplication  (0) 2023.12.19
자동 구성, 스프링 부트 3와 자바 버전  (0) 2023.12.19
스프링 부트 스타터  (0) 2023.12.19