작성
·
201
답변 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";
}
}
감사합니다.