Both @Controller and @RestController annotations are used to define controller classes in Spring Boot, but with different purposes and use cases. @Controller Example A general-purpose annotation for defining controller classes that can return views or response bodies, depending on the use of the @ResponseBody annotation. Controllers annotated with @Controller are typically used when you want to create web pages and return HTML views. They are part of the traditional Spring MVC approach, where the controller methods return the names of views to be resolved by the view resolver. Java import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; @Controller public class MyController { @GetMapping("/hello") public String hello() { return "hello"; // Returns the view name (e.g., hello.jsp or hello.html) } } @RestController A specialized version of @Controller that assumes all methods return the response body directly, without the need for a @ResponseBody annotation. It is commonly used for RESTful web services. Controllers annotated with @RestController are used to build RESTful APIs that return data in a format like JSON or XML directly to the client. The return value of the methods is serialized directly into the response body. Java import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class MyRestController { @GetMapping("/api/hello") public String hello() { return "Hello, World!"; // Returns the string directly in the response body } } Reference: MVC Controller