Home  >  Forum  >  Spring
Post New Query

what is the controller return type in spring?



Asked on December 08, 2013
any body please send to me please this is my mail id
srinivasthangallapally@gmail.com



Replied on December 08, 2013
In Spring MVC, the below return types are possible.

1. ModelAndView 
2. Model 
3. Map 
4. View 
5. String
6. void
7.  Callable<?> : if application wants return asynchronously in thread managed MVC
8. When method is annotated with @ResponseBody, the return type is written directly to the response HTTP body.

@RequestMapping(value = "/somepattern", method = RequestMethod.PUT)
@ResponseBody
public String doTask()  {
  return "Hello World";
}

9. Set values in response header using HttpEntity as given below

  HttpHeaders responseHeaders = new HttpHeaders();
  responseHeaders.set("SomeResponseHeader", "some Value");
  return new ResponseEntity<String>("Some Message", responseHeaders, HttpStatus.CREATED);

10.  DeferredResult<?> 

Find the link below  for more detail from spring Doc


Write Answer








©2019 concretepage.com | Privacy Policy | Contact Us