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

标签 java thymeleaf hashset

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

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/

相关文章:

spring - Thymeleaf + Boot + AngularJS指令解析器错误

java - 使用多个表单在 View 上提交表单时出现 Spring "Neither BindingResult nor plain target object for bean name"错误

node.js - 我想使用 NodeJS 中的 redis 库在 Redis 中的 hset 特定键中设置 Expiry

java - HashSet 与 ArrayList

java - 在Java中将集合的集合转换为列表的列表

Java : startsWith() with different prefix and not only one

java - 在java中分配引用变量(示例)

java - 如何使用 JAVA 将项目添加到 Mac OS X 中的 Finder 上下文菜单?

java - IntelliJ Gradle 无法确定 Java 版本

java - Spring Boot Thymeleaf 显示不工作