2014-03-30 35 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; 
} 
相關問題