我在下面有以下代码。 Thymeleaf无法解决" orderDetails"尽管当我通过Thymeleaf的内部调试时该字段存在/不为空。
异常=字段或属性' 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>
以下是&#34; order&#34;的问题。现场/班。
@OneToMany(fetch = FetchType.EAGER, mappedBy = "barOrder")
@JsonProperty
private Set<OrderDetail> orderDetails;
答案 0 :(得分:3)
需要使用orderDetails字段的公共getter方法来允许Thymeleaf访问它。
public Set<OrderDetail> getOrderDetails() {
return orderDetails;
}