인프런 커뮤니티 질문&답변
@Controller
작성
·
208
퀴즈
66%나 틀려요. 한번 도전해보세요!
실제 서비스 개발에서 System.out.println 대신 로깅 라이브러리를 사용하는 주된 이유가 무엇일까요?
코드가 더 짧아져요.
성능이 훨씬 빨라요.
로그 레벨 설정으로 출력 레벨을 조절할 수 있어요.
다른 개발자가 보기에 더 멋있어요.
답변 1
1
안녕하세요. australialove19님, 공식 서포터즈 OMG입니다.
오늘 질문을 많이 하시네요 ㅎㅎ
열심히 하시는 모습 보기 좋습니다.
@RestController는 @Controller + @ResponseBody라고 이해하시면 편합니다.
@Controller는 @RestController에서 @ResponseBody가 빠진 것이라고 보셔도 됩니다.
@Controller는 @Component와 거의 비슷합니다.
거의라고 한 이유는 다음과 같은 차이가 있으며 영한님의 스프링핵심원리 기본편 강좌에서 설명하고 계십니다.
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Controller {
/**
* The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component.
* @return the suggested component name, if any (or empty String otherwise)
*/
@AliasFor(annotation = Component.class)
String value() default "";
}
@Controller의 경우 return 에 해당하는 문자열의 이름에 해당하는 html, jsp 등의 파일을 찾습니다.
@Controller
public class BookController {
@GetMapping("/books")
public String books() {
return "book";
}
}
감사합니다.




