Spring @RestController example

In this post,  we are going to see another important annotation called @RestController. It is generally used while working with Spring restful Web services implementation.

Spring MVC tutorial:

If we need to directly get resource from controller, we need to return @ResponseBody as per Spring 3 but with Spring 4, we can use @RestController for that.
In spring 4.0, we can use @RestController which is combination of @Controller + @ResponseBody.

So

Is same as

Instead of annotating each method return type as @ResponseBody, we can directly annotate a class with @RestController. You can see Spring rest Json example to get complete working example on @RestController.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *