gpt4 book ai didi

java - thymeleaf : How to access elements of hash set one by one?

转载 作者:行者123 更新时间:2023-12-02 12:16:36 25 4
gpt4 key购买 nike

我正在创建一个哈希集,如下所示。

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com