gpt4 book ai didi

thymeleaf - 如何检查该 map 是否包含使用 thymeleaf 的特定 key

转载 作者:行者123 更新时间:2023-12-02 07:30:14 28 4
gpt4 key购买 nike

我正在使用 thymeleaf对于表示层,因此我从 Controller 发送包含键和值列表的 map ,如下所示 Map<Long,List<Long>>到 x.html。但是我如何使用 thymeleaf 检查 x.html 中的 map 中是否包含 key ,所以请告诉我检查它的方法

我尝试过这种方式,但没有成功

<span th:if="${#maps.containsKey(myMap, myStringValue)}">YEAH!</span>

最佳答案

从 Thymeleaf 1.0 版开始,您就描述了这种方法,它按预期对我有效(请参阅 documentation)。也许您的 Map 键不是 String 值或 myStringValue 不是 String

您是否尝试过使用常量 String 作为键?

<span th:if="${#maps.containsKey(myMap, 'valueOfMyStringValue')}">YEAH!</span>

或者直接在Map上调用Map#containsKey方法?

<span th:if="${myMap.containsKey('valueOfMyStringValue')}">YEAH!</span>

关于thymeleaf - 如何检查该 map 是否包含使用 thymeleaf 的特定 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22559367/

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