What is difference between @controller and @restcontroller?

  • @Controller used to mark a class as a web request handler. It’s mostly used with Spring MVC application.
  • The @Controller annotation indicates that a particular class serves the role of a controller
  • @RestController is a annotation that is combination of the @Controller and @ResponseBody annotations .
  • In @RestController, we don’t need to use @ResponseBody on every handler method.

So the following two controller  should do the same.

@RestController= @Controller+@ResponseBody.

@Controller
@ResponseBody
public class MyController { }

@RestController
public class MyRestController { }

What is difference between @controller and @restcontroller? Read More »