컨트롤러는 view가 있을때 사용해서 html을 리턴함
만약 컨트롤러일때는 sparta라는 html이 존재하면 return "sparta"라고 하면 스파르타 html 열림
레스트 컨트롤러는 리스폰스바디 있을때 사용해야함 데이터를 그대로 리턴함
return "sparta" 하면 그냥 문자열 sparta가 반환됨
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
@ResponseBody
public @interface RestController {
@AliasFor(
annotation = Controller.class
)
String value() default "";
}
@RestController의 내부를 보면 컨트롤러에 @ResponseBody를 더해놓은 것이다.
그렇기 때문에 데이터를 그대로 리턴하는 것이다!
'spring' 카테고리의 다른 글
| 같은 타입의 Bean 충돌 해결(@Qualifier @Primary) (0) | 2025.02.04 |
|---|---|
| 의존관계 주입 / @RequiredArgsConstructor (0) | 2025.02.04 |
| 수동등록 bean(@Configuration, @Bean)과 자동등록 bean(@ComponentScan, @Component)이 충돌할 경우 (0) | 2025.02.04 |
| MVC와 템플릿 엔진, API (0) | 2025.01.31 |
| View 환경설정 (3) | 2025.01.31 |