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

    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 provide any additional JSON dependency in the classpath. Spring […]

  • 14 September

    Spring Rest + Spring Security example

    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 SOAP and REST web services SOAP web service example in java using eclipse JAX-WS web service eclipse tutorial JAX-WS […]

  • 17 August

    Spring Rest Hibernate example

    In previous post, we have already seen Spring Rest crud example . In this post, we will extend same example and integrate it with hibernate and mysql. We will use following annotations for CRUD operation. Method Description Get It is used to read resource Post It is used to create new resource. It is not […]

  • 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

    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 Component,Service, Repository and Controller example Spring MVC @ModelAttribute annotation example Spring MVC @RestController annotation example Spring MultiActionController Example Spring […]

  • 04 August

    Spring Restful web services xml example

    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 introduction Difference between SOAP and REST web services SOAP web service example in […]

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.