Easy Spring Boot Question 62 of 226

What is the difference between @Controller and @RestController?

Java Specialist · Speak this in 60–90 seconds · Faridabad & Delhi NCR

PICTURE THIS: A REST CALL

ClientGET /users/1
ServerFind row
JSON back200 OK

Simple meaning

@Controller is for MVC that returns view names

1

WHY — Spring Boot instead of guessing?

Why interviewers care about Spring Boot:

They want a clean

contrast on Spring Boot, not two memorised paragraphs.

Say what changes for

the developer, then one case where picking wrong hurts.

Stay structured

Name the idea, why it exists, then one short example.

Close cleanly

End with when you use it and one common pitfall.

2

STEPS — What happens step by step?

Before you speak the answer, walk the interviewer through these steps:

  1. 1
    @Controller is for MVC

    that returns view names

  2. 2
    you need @ResponseBody on

    methods that return JSON.

  3. 3
    @RestController is @Controller plus

    @ResponseBody on every method, which is what REST APIs want.

  4. 4
    For a JSON backend

    interview, @RestController is the expected default.

  5. 5
    Common mistake

    What juniors usually get wrong.

  6. 6
    Close

    When you pick this over the alternative.

3

EXAMPLE — See it in action

Here's a short line you can speak, broken into clear beats:

Say this line
“@RestController is @Controller plus @ResponseBody on every method, which is what”
Break into beats
RestControllerisControllerplusResponseBodyon
Speaking order
2987408337471632900

Note: Adapt this scaffold to your own project — keep it under 60–90 seconds.

Key takeaway

@Controller is for MVC that returns view names you need @ResponseBody on methods that return JSON.

Chat with us