我在Spring Controller中有这个功能:
@ModelAttribute("findOrderItemsByOrderId")
public Set<OrderItem> findOrderItemsByOrderId(Long id) {
return orderItemService.findByOrder(orderService.findById(id));
}
这个循环在我的JSP文件中:
<c:forEach items="${findOrderItemsByOrderId}" var="orderItem">
${orderItem.product.name}
${orderItem.quantity}
${orderItem.product.price}
</c:forEach>
我必须将命令的id传递给我的函数,但我不知道如何。我试图做这样的事情(显然不是正确的):
@ModelAttribute("findOrderItemsByOrderId/{id}")
public Set<OrderItem> findOrderItemsByOrderId(@PathVariable Long id) {
return orderItemService.findByOrder(orderService.findById(id));
}
<c:forEach items="${findOrderItemsByOrderId/${order.id}}" var="orderItem">
${orderItem.product.name}
${orderItem.quantity}
${orderItem.product.price}
</c:forEach>