Is it possible in Spring MVC to have void handlers for requests?


Is it possible in Spring MVC to have void handler for request?

Suppose I have a simple controller, which doesn't need to interact with any view.

@Controller @RequestMapping("/cursor") public class CursorController { @RequestMapping(value = "/{id}", method = PUT) public void setter(@PathVariable("id") int id) { AnswerController.setCursor(id); } }


@Controller @RequestMapping("/cursor") public class CursorController { @RequestMapping(value = "/{id}", method = PUT) public ResponseEntity<String> update(@PathVariable("id") int id) { AnswerController.setCursor(id); return new ResponseEntity<String>(HttpStatus.NO_CONTENT); } }


you can return void, then you have to mark the method with

@ResponseStatus(value = HttpStatus.OK) you don't need @ResponseBody

@RequestMapping(value = "/updateSomeData" method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.OK) public void defaultMethod(...) { ... }

Only get methods return a 200 status code implicity, all others you have do one of three things:

Return void and mark the method with @ResponseStatus(value = HttpStatus.OK)

Return An object and mark it with @ResponseBody

Return an HttpEntity instance

Also refer this for <a href="http://ankursinghal86.blogspot.in/2014/08/spring-mvcs-default-behavior.html" rel="nofollow">interesting information</a>.


  • JavaFX set mouse hidden when idle
  • Elasticsearch Rest Client Still Giving IOException : Too Many Open Files
  • How can I set a description and an example in Swagger with Swagger annotations?
  • SpringBoot+Hibernate+Restful : format response
  • Unable to consume JSON array using Spring RestTemplate
  • How to create Spring Data Rest entities response format manually [duplicate]
  • Spring Boot + Angular file upload unable to upload same file twice
  • 'Too many body parameters' Exception on Feign Client
  • Match generics with Mockito
  • Content-length is null for EntityTemplate
  • Spring + Angular Unable to upload same file twice
  • PyQt4 - QGraphicsItem position doesn't map into scene properly after drag
  • springboot jackson returns array instead of proper json object
  • Bind a String value to an enum in a @RequestBody entity in Spring Boot
  • No default constructor found exception
  • How to convert Image to multipart file in spring
  • Symfony YAML format conversion
  • WPF ClickOnce missed references
  • Do I need to reset a Perl hash index?
  • Java: can you cast Class into a specific interface?
  • How to access EntityManager inside Entity class in EJB3
  • AES padding and writing the ciphertext to a disk file
  • Updating server-side rendering client-side
  • How to extract text from Word files using C#?
  • Trying to switch camera back to front but getting exception
  • Cannot Parse HTML Data Using Android / JSOUP
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Free memory of cv::Mat loaded using FileStorage API
  • JTable with a ScrollPane misbehaving
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • How to stop GridView from loading again when I press back button?
  • unknown Exception android
  • Programmatically clearing map cache
  • Observable and ngFor in Angular 2
  • failed to connect to specific WiFi in android programmatically
  • Unable to use reactive element in my shiny app
  • How can I use threading to 'tick' a timer to be accessed by other threads?