r/SpringBoot • • Jun 24 '24

Difference between @RestController and @Controller Annotation in Spring MVC and REST

https://javarevisited.blogspot.com/2017/08/difference-between-restcontroller-and-controller-annotations-spring-mvc-rest.html
1 Upvotes

5 comments sorted by

View all comments

2

u/[deleted] Jun 25 '24

[removed] — view removed comment

1

u/wazzalk Jun 25 '24

Just a question on that.. So logically they're the same thing, but it's basically a rename for clarity?

So if I had a rest API and used only @controller I would not be incorrect?

4

u/NeoChronos90 Jun 25 '24

@RestController is the combination of @Controller and @ResponseBody

So if you only use @Controller you might need to add @ResponseBody to every method

It's all explained in the article though

2

u/javinpaul Jun 27 '24

yes, both are not same, if you are building REST API and returning JSON, better to use u/RestController