Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (4k points)
Difference between spring @Controller and @RestController annotation.

Can @Controller annotation be used for both Web MVC and REST applications?

If yes, how can we differentiate if it is Web MVC or REST application?

1 Answer

0 votes
by (46k points)
  • @Controller is applied to point classes as Spring MVC Controller.
  • @RestController is a support annotation that does nothing more extra than combining the @Controller and @ResponseBody footnotes check: Javadoc

So the resulting two-controller definitions should do the likewise

@Controller

@ResponseBody

public class MyController { }

@RestController

public class MyRestController { }

Browse Categories

...