What are the differences between @Controller and @RestController annotations?

@Controller and @RestController both mark a class as a Spring MVC web controller, but they differ in what a method's return value is assumed to mean by default.

Key Points

Example

A method in a @Controller returning "dashboard" causes Spring to render dashboard.jsp, whereas the same method in a @RestController returning a DTO would be serialized straight into a JSON response with no view resolution involved.

Interview Tip

A concise interview answer is

@Controller is for classes rendering views, where returning a String means a view name and JSON output needs an explicit @ResponseBody. @RestController bundles @ResponseBody in by default, so every method's return value is serialized directly as the response body, which is exactly what you want for a REST API.

Last updated: 16 July 2026

Previous question: How does @RequestMapping handle different types of HTTP requests?

Next question: When would you use @RestController instead of @Controller?

More Spring MVC (Optional) interview questions

All Spring MVC (Optional) questions