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.


import_contacts

You may also like:


import_contacts

You may also like:

Related Posts

  • 29 April

    Spring boot rest example

    Table of ContentsSpring Boot Rest example:Github Source code:Project structure: In this tutorial, we will see how to create Restful web services using Spring boot. There are not many differences between creating Rest API using Spring Rest JSON which we have already seen earlier. Spring Boot just makes easier to Rest API. You don’t have to […]

  • 14 September

    Spring Rest + Spring Security example

    Table of ContentsRun the applicationIf you getting 404 error with above steps, you may need to follow below steps: In this post , we are going to apply Spring Security on Spring Rest example. Web services tutorial: Introduction to web services Web services interview questions SOAP web service introduction RESTful web service introduction Difference between […]

  • 17 August

    Spring Rest Hibernate example

    Table of ContentsSource code:Maven dependenciesCreate bean classCreate ControllerCreate DAO classCreate Service classRun the applicationPost methodPut MethodIf you getting 404 error with above steps, you may need to follow below steps: In previous post, we have already seen Spring Rest crud example . In this post, we will extend same example and integrate it with hibernate […]

  • 08 August

    Spring MVC @RequestMapping annotation example

    We have already seen Spring MVC hello world example. @RequestMapping is one of important annotation which you use in Spring MVC. Spring MVC tutorial: Spring MVC hello world example Spring MVC Hibernate MySQL example Spring MVC interceptor example Spring MVC angularjs example Spring MVC @RequestMapping example Spring Component,Service, Repository and Controller example Spring MVC @ModelAttribute annotation […]

  • 06 August

    Spring MVC angularjs example

    Table of ContentsSpring MVC tutorial:Github Source code:Maven dependenciesApplication configuration:Create bean classCreate ControllerCreate Service classAngularJS viewRun the applicationProject structure:AngularJS tutorial: n this tutorial, we will see Spring MVC angularjs example. Spring MVC tutorial: Spring MVC hello world example Spring MVC Hibernate MySQL example Spring MVC interceptor example Spring MVC angularjs example Spring MVC @RequestMapping example Spring […]

  • 04 August

    Spring Restful web services xml example

    Table of ContentsWeb service Tutorial Content:Spring application configuration:Create bean classCreate controllerRun the application This post is in continuation with web service tutorial (Part -10). In this tutorial,we are going to see Spring Restful web services xml example. Web service Tutorial Content: Introduction to web services Web services interview questions SOAP web service introduction RESTful web service […]

Leave a Reply

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

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.