我正在创建一个哈希集,如下所示。
public Set<InventoryPriceRange> getPriceRanges() {
if(priceRanges == null){
priceRanges = new HashSet<>();
}
return priceRanges;
}
现在我想使用 thymeleaf 来一一访问它的元素。我目前正在这样做
th:value="${IR.priceRanges[1]}
th:value="${IR.priceRanges[2]}
th:value="${IR.priceRanges[3]}
输出仅显示此内容而不是值。
com.vlclabs.adsops.domain.deal.InventoryPriceRange@1f1f61a4
这是 com.vlclabs.adsops.domain.deal.InventoryPriceRange 下的代码。这用于设置哈希集的值。
private Long id;
private double lowerLimit;
private boolean equalLowerLimit;
private double upperLimit;
private boolean equalUpperLimit;
private double price;
public InventoryRow getInventoryRow() {
return inventoryRow;
}
public void setInventoryRow(InventoryRow inventoryRow) {
this.inventoryRow = inventoryRow;
}
}
我是 thymeleaf 新手。请帮我解决这个问题。
最佳答案
关于访问 thymeleaf 中的集合的一种机制如下:
<tr th:each="message : ${messages}">
<td th:text="${message.id}">1</td>
<td><a href="#" th:text="${message.title}">Title ...</a></td>
<td th:text="${message.text}">Text ...</td>
</tr>
说明:${message} - 将其替换为您的集合 探索以上几行并做出改变 上面的集合名称应该是您正在返回的模型属性名称。
关于java - thymeleaf : How to access elements of hash set one by one?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46127445/