Created
January 7, 2014 06:24
-
-
Save yanhua365/8295380 to your computer and use it in GitHub Desktop.
Spring MVC REST 实现返回不同状态的控制器,代码来自:http://spring.io/guides/tutorials/rest/2/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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