Created
January 7, 2014 02:07
-
-
Save yanhua365/8293601 to your computer and use it in GitHub Desktop.
Spring MVC中用一个独立的私有方法指定@ModelAttribute属性。代码来源于:http://spring.io/guides/tutorials/web/5/
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
@Controller | |
@RequestMapping("/order/{orderId}") | |
public class OrderStatusController { | |
private static final Logger LOG = LoggerFactory | |
.getLogger(OrderStatusController.class); | |
@Autowired | |
private OrderService orderService; | |
@RequestMapping(method = RequestMethod.GET) | |
public String orderStatus(@ModelAttribute("orderStatus") OrderStatus orderStatus) { | |
LOG.debug("Get order status for order id {} customer {}", orderStatus.getOrderId(), orderStatus.getName()); | |
return "/order"; | |
} | |
@ModelAttribute("orderStatus") | |
private OrderStatus getOrderStatus(@PathVariable("orderId") String orderId) { | |
OrderStatus status = orderService.requestOrderStatus(orderId); | |
return status; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment