What is the difference between @RestController and @Controller in Spring Boot?

  • @Controller is used for MVC applications and returns HTML by default.
  • @Controller is used for RESTful APIs and returns JSON by default.
  • @RestController is used for MVC applications and returns HTML by default.
  • @RestController is used for RESTful APIs and returns JSON by default.
The key difference is that @RestController is specifically designed for RESTful APIs and returns data in JSON format by default, while @Controller is used for traditional MVC applications and returns HTML by default. Mixing them up can lead to unexpected results, so choosing the right annotation is crucial for the desired functionality.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *