@Controller
public class RestClassName{
@RequestMapping(value={"/uri"})
@ResponseBody
public ObjectResponse functionRestName(){
//...
return instance
}
}
@RestController
public class RestClassName{
@RequestMapping(value={"/uri"})
public ObjectResponse functionRestName(){
//...
return instance
}
}
두 코드의 차이처럼 @RestController는 @ResponseBody가 기본적으로 추가되며,
response를 JSON/XML로 자동 변환해준다.
@RestControllerAdvice도 마찬가지로 @ControllerAdvice에 @ResponseBody가 기본값으로 추가된 것을 의미한다.
Difference between spring @Controller and @RestController annotation
Difference between spring @Controller and @RestController annotation. Can @Controller annotation be used for both Web MVC and REST applications? If yes, how can we differentiate if it is Web MVC o...
stackoverflow.com
ref 2 : https://stackoverflow.com/questions/43124391/restcontrolleradvice-vs-controlleradvice
@RestControllerAdvice vs @ControllerAdvice
What are the major difference between @RestControllerAdvice and @ControllerAdvice ?? Is it we should always use @RestControllerAdvice for rest services and @ControllerAdvice MVC ?
stackoverflow.com
'Spring Boot' 카테고리의 다른 글
[Spring] CrudRepository vs JpaRepository (0) | 2021.10.13 |
---|---|
[Spring] 매일 자정 특정 동작 수행하기 (schedule, cron) (0) | 2021.10.12 |
[JPA] FetchType Eager와 Lazy 차이점 (0) | 2021.04.30 |
[JPA] @Transient (0) | 2021.04.27 |
[Spring Boot] Hello World 프로젝트 생성 (0) | 2021.04.13 |