Skip to content

Instantly share code, notes, and snippets.

@yanhua365
Created January 7, 2014 02:07
Show Gist options
  • Save yanhua365/8293601 to your computer and use it in GitHub Desktop.
Save yanhua365/8293601 to your computer and use it in GitHub Desktop.
Spring MVC中用一个独立的私有方法指定@ModelAttribute属性。代码来源于:http://spring.io/guides/tutorials/web/5/
@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