@RestController is a Spring MVC stereotype annotation that combines @Controller and @ResponseBody, so every method's return value is written directly to the HTTP response body instead of being resolved to a view. @Controller, by contrast, expects methods to return a logical view name that gets rendered into HTML by a view resolver.
A shopping site might use @RestController for a /api/products endpoint that returns a JSON list consumed by a JavaScript front end, while using @Controller for a /checkout endpoint that renders an HTML page with Thymeleaf.
A concise interview answer is
I use @RestController for API endpoints that return data like JSON directly, since it bakes in @ResponseBody on every method. I use @Controller when the method needs to return a view name for server-side rendering, such as a JSP or Thymeleaf page.
Last updated: 11 November 2026
Previous question: What are the differences between @Controller and @RestController annotations?
Next question: How does response handling differ between @Controller and @RestController?