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);
}
}
UPD
@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
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
instanceAlso refer this for interesting information.