본문 바로가기

내가 당면한 문제와 해결방안

@RestController @Controller 차이

@RestController @Controller diff 

 

@RestController = @Controller + @ResponseBody

RestClient는 보통 프로그램이므로 응답할때는 JSON이나 XML 으로 해줘야하는데 RestController가 이런 응답시 적합한 애노테이션

 

 

The @RestController annotation in Spring MVC is nothing but a combination of @Controller and @ResponseBody annotation. It was added into Spring 4.0 to make the development of RESTful Web Services in Spring framework easier. If you are familiar with the REST web services you know that the fundamental difference between a web application and a REST API is that the response from a web application is generally view (HTML + CSS + JavaScript)  because they are intended for human viewers while REST API just return data in form of JSON or XML because most of the REST clients are programs. This difference is also obvious in the @Controller and @RestController annotation.

 

The job of @Controller is to create a Map of model object and find a view but @RestController simply return the object and object data is directly written into HTTP response as JSON or XML.


Read more: https://javarevisited.blogspot.com/2017/08/difference-between-restcontroller-and-controller-annotations-spring-mvc-rest.html#ixzz62g1n2VUB

'내가 당면한 문제와 해결방안' 카테고리의 다른 글

데이터마이그레이션  (0) 2019.10.22
List vs ArrayList in java  (0) 2019.10.18
elasticsearch geo queries  (0) 2019.09.06
couchbase  (0) 2019.08.29
spring  (0) 2019.08.17