Public class Auction{
private int auctionid;
Private list<Auctionrecord>
auctionrecord List;
}
Public class Auctionrecord{
Private Users users;}
Public class Users{
Private int id;
Private string name;
}
controller 返回很多个Auction对象,然后auction里面的auctionrecord的user怎么在 th:each遍历出来
用Thymeleaf的嵌套th:each语法来遍历一对多关系的数据
<table>
<thead>
<tr>
<th>Auction ID</th>
<th>User ID</th>
<th>User Name</th>
</tr>
</thead>
<tbody>
<tr th:each="auction : ${auctions}">
<td th:text="${auction.auctionid}"></td>
<td></td>
<td></td>
<td>
<table>
<tbody>
<tr th:each="auctionRecord : ${auction.auctionrecordList}">
<td></td>
<td th:text="${auctionRecord.users.id}"></td>
<td th:text="${auctionRecord.users.name}"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>