Spring Boot Interview Question

What is the difference between Controller and RestController?

Updated 2026-07-10 · Beginner friendly
Quick answer

Controller is used when methods return a view name, such as an HTML page, and you need ResponseBody on individual methods to return data. RestController is a shortcut that combines Controller and ResponseBody, so every method returns data directly, usually as JSON. Use RestController for REST APIs and Controller when serving web pages.

Controller

A method in a Controller returns a view name by default, which a template engine turns into HTML. To return raw data you must add ResponseBody to the method.

RestController

This is Controller plus ResponseBody applied to the whole class, so every method returns the data itself. This is what you want for JSON APIs.

@RestController   // = @Controller + @ResponseBody
class ApiController {
    @GetMapping("/user")
    User get() { return new User(); }  // returned as JSON
}
In the interview

The clean answer is RestController equals Controller plus ResponseBody, so use it for REST APIs and plain Controller for server rendered pages. Stating that equation is the crispest way to show you understand the link.

Want the full Spring Boot guide?

Read every Spring Boot concept with notes, diagrams, and code in one place. Track your progress as you go.

Open the Spring Boot guide All Spring Boot questions