I am using jQuery's $.getJSON()
to make asynchronous calls to my simple Spring MVC backend. Most of the Spring controller methods look like this:
@RequestMapping(value = "/someURL", method = RequestMethod.POST)
public @ResponseBody SomePOJO getSomeData(@ModelAttribute Widget widget,
@RequestParam("type") String type) {
return someDAO.getSomeData(widget, type);
}
I have things set up so that each controller returns the @ResponseBody
as JSON, which is what the client-side expects.
But what happens when a request isn't supposed to return any content to the client-side? Can I have:
@RequestMapping(value = "/updateSomeData" method = RequestMethod.POST)
public @ResponseBody void updateDataThatDoesntRequireClientToBeNotified(...) {
...
}
If not, what's the appropriate syntax to use here?
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 updateDataThatDoesntRequireClientToBeNotified(...) {
...
}
Only get methods return a 200 status code implicity, all others you have do one of three things:
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
HttpEntity
instance