@Controller vs @RestController Difference
Fast recall
Quick revision
Core answer
Understanding the difference between traditional MVC and RESTful API response models
Using @Controller for a REST API and forgetting @ResponseBody on every method, causing Spring to look for view templates that don't exist
Explain that @ResponseBody triggers HttpMessageConverters like Jackson to serialize return values into JSON, and that @RestController is a convenience meta-annotation
Interview-ready guide
Interview answer
Choose @Controller for server-rendered MVC when methods normally return a view name and place attributes in Model. Choose @RestController for an API whose methods normally return DTOs, ResponseEntity values, or other response bodies. The difference is default return-value handling, not routing: both use the same request mapping infrastructure. A @Controller method can become an API endpoint with @ResponseBody, and a RestController result is written by a compatible HttpMessageConverter based on content negotiation.
@Controller vs @RestController Difference
Direct Answer
@Controller registers an MVC controller whose methods may resolve views or write response bodies. @RestController is @Controller plus class-level @ResponseBody, so its method results are handled as response-body data by message converters. A @Controller is not limited to view names: individual methods can use @ResponseBody or return ResponseEntity.
Common Mistakes & Pitfalls
- Using @Controller for REST APIs: Freshers see tutorials using @Controller, copy it for a REST API, and get 404 errors because Spring tries to resolve user-list as a Thymeleaf template. Solution: switch to @RestController or add @ResponseBody to every method.
- Mixing concerns in one controller: Putting HTML-rendering methods and JSON endpoints in the same class creates confusion. Split them: UserViewController with @Controller, UserApiController with @RestController.
- Forgetting @ResponseBody: When using @Controller for a hybrid app, freshers forget @ResponseBody on JSON endpoints and spend hours debugging why the API returns 404 instead of JSON.
Check your understanding
Answer these without looking back at the article.
- What is @ResponseBody and what does it do?
- Can you add @ResponseBody to individual methods in @Controller?
- What is Spring MVC's view resolution?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.