Home  >  Forum  >  Spring
Post New Query

How to use @RestController in Spring 4?


joined on
March 22,2015
Asked on March 22,2015

Hi Friends,


In Spring 4 new feature,  a new annotation @RestController has been introduced.  How to use @RestController in Spring 4? Thanks



joined on
October 10,2013
Replied on March 22,2015

@RestController  is itself annotated by @Controller and @ResponseBody annotation.   @RestController is used for REST web services.  Now the web service method need not to use @ResponseBody, if our service class has been annotated with  @RestController. We can create our web service class as

@RestController
@RequestMapping("/data")
public class PersonController {
}

Within this class we can create our web service method as

@RequestMapping("/person")
public Person getPersonDetail(@RequestParam(value = "id",required = false,
                                                defaultValue = "0") Integer id) {
return person;
}

Find the URL for complete example of  @RestController in Spring 4.



Write Answer









Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us