InterviewSolution
| 1. |
Explain the difference between @Controller and @RestController annotation? |
|
Answer» Traditional Spring controllers are created by ADDING a class with @Controller annotation. It is actually a specialization of the @Component annotation that allows the implementation classes to be autodetected by Spring context through the CLASSPATH scanning. Generally, @Controller annotation is used in combination with @RequestMapping and @ResponseBody added to the request handling methods to define the REST APIS. @RestController is a convenient annotation that combines both the features of @Controller and @ResponseBody annotations. The KEY difference between typical Spring @Controller and the RESTful web service @RestController is the way the HTTP response body is created. While the traditional MVC controller relies on the View technology, the RESTful web service controller returns the object and the object data is written directly to the HTTP response as JSON. |
|