Skip to content

Instantly share code, notes, and snippets.

@yanhua365
Created January 7, 2014 06:24
Show Gist options
  • Select an option

  • Save yanhua365/8295380 to your computer and use it in GitHub Desktop.

Select an option

Save yanhua365/8295380 to your computer and use it in GitHub Desktop.
Spring MVC REST 实现返回不同状态的控制器,代码来自:http://spring.io/guides/tutorials/rest/2/
@RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
public ResponseEntity<Order> cancelOrder(@PathVariable String id) {
OrderDeletedEvent orderDeleted = orderService.deleteOrder(new DeleteOrderEvent(UUID.fromString(id)));
if (!orderDeleted.isEntityFound()) {
return new ResponseEntity<Order>(HttpStatus.NOT_FOUND);
}
Order order = Order.fromOrderDetails(orderDeleted.getDetails());
if (orderDeleted.isDeletionCompleted()) {
return new ResponseEntity<Order>(order, HttpStatus.OK);
}
return new ResponseEntity<Order>(order, HttpStatus.FORBIDDEN);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment