2014-03-30 36 views
1

我在下面有下面的代码。 Thymeleaf无法解决“orderDetails”问题,尽管当我通过Thymeleaf的内部进行调试时该字段存在/不为空。在Thymeleaf中找不到字段(自定义POJO列表)?

异常=字段或属性“ORDERDETAILS”不能在类型

<div th:each="order : ${orders}"> 
<table> 
     <tr> 
     <th>CUSTOMER</th> 
     <th>PRICE</th> 
     <th>TIME ORDER PLACED</th> 
     <th>ITEMS</th> 
     </tr> 

     <tr> 
     <td th:text="${order.customerAccount.email}">email</td> 
     <td th:text="${order.baseCost}">2.50</td> 
     <td th:text="${order.tip}">2.00</td> 
     <td th:text="${order.orderDetails}">2.00</td> 
     <!-- <td th:text="${#lists.size(order.orderDetails)}">1</td> --> 
     </tr> 

    </table> 

    <table> 
     <tr> 
     <th>DRINK NAME</th> 
     <th>AMOUNT</th> 
     <th>QUANTITY</th> 
     <th>COST</th> 
     </tr> 

     <tr th:each="orderDetail : ${order.orderDetails}"> 
     <td th:text="${orderDetail.barStock.drink.name}">Test Drink Name</td> 
     <td th:text="${orderDetail.barStock.amount}">10oz</td> 
     <td th:text="${orderDetail.quantity}">2</td> 
     <td th:text="${orderDetail.barStock.cost * orderDetail.quantity}">2.00</td> 
     </tr> 

    </table> 

这里的对象中找到在“命令”字段/类的问题领域。

@OneToMany(fetch = FetchType.EAGER, mappedBy = "barOrder") 
@JsonProperty 
private Set<OrderDetail> orderDetails; 
+2

您是否拥有orderDetails字段的公共getter方法? –

+0

/facepalm ... nooooooo:X – Zerkz

+0

随意将其作为答案,以便我可以给你信用。 – Zerkz

回答

3

为了让Thymeleaf能够访问它,需要一个orderDetails字段的公共getter方法。

public Set<OrderDetail> getOrderDetails() { 
    return orderDetails; 
} 
相关问题