728x90
@Controller
• 주로 View를 반환하기 위해 사용
Controller가 반환한 뷰의 이름으로부터 View를 렌더링하기 위해 ViewResolver가 사용되고, ViewResolver 설정에 맞게 View를 찾아 렌더링한다.
• Data를 반환해야 하는 경우
데이터 반환을 위해 @ResponseBody 어노테이션을 활용하여 Controller로 Json 형태로 데이터를 반환할 수 있다.
Controller를 통해 객체를 반환할 때 일반적으로 ResponseEntity로 감싸서 반환한다.
@RestController
@Controller + @ResponseBody
주용도는 Json 형태로 객체 데이터를 반화하는 것
REST API 개발할 때 주로 사용하며 객체를 ResponsEntity로 감싸서 반환한다.
참고
728x90
'Spring' 카테고리의 다른 글
[Spring] @NoArgsConstructor, @AllArgsConstructor, @RequiredArgsConstructor (0) | 2024.09.20 |
---|---|
[Spring] @RequestMapping (0) | 2024.09.18 |
[Spring] @Transactional 안 되는 경우 (0) | 2024.09.13 |
[Spring] Swagger 적용(Springboot 3.x) (0) | 2024.09.11 |
[Spring] ERROR : Unable to find a single main class from the following candidates (0) | 2024.09.09 |