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.
Loading...
Related Quiz
- Which of the following is true about the deleteById method of a JpaRepository?
- What is the primary role of the UserDetailsService in Spring Security?
- In Spring Boot, which annotation is used to define a class as a global advice for all controllers?
- How would you implement a custom caching strategy in Spring Boot if the default ones do not meet your requirements?
- Which annotation is used to bind the value of a method parameter to a named HTTP header in a Spring Boot application?