如何使用 thymleaf 检查该地图是否包含特定密钥
我使用 thymeleaf
作为表示层,所以我从控制器发送包含键和值列表的地图,就像这样 Map
代码> 到 x.html.但是我如何使用 thymeleaf 检查 x.html 中的 map 中是否包含密钥,所以请告诉我检查它的方法
I am using the thymeleaf
for presentation layer, so from controller i am sending the map containing key and list of values like this Map<Long,List<Long>>
to x.html. But how i check whether the key contained in map in x.html using thymeleaf so please tell me the way to check it
我试过这种方法但没有成功
i tried this way but not successfull
<span th:if="${#maps.containsKey(myMap, myStringValue)}">YEAH!</span>
自从 Thymeleaf 1.0 版以来,您描述的这种方法按预期对我有用(请参阅 文档).也许您的 Map
键不是 String
值或 myStringValue
不是 String
.
There is such method you described since Thymeleaf version 1.0 which works for me as expected (see documentation). Maybe your Map
key isn't String
value or myStringValue
isn't String
.
您是否尝试使用常量 String
作为键?
Did you tried use constant String
as key?
<span th:if="${#maps.containsKey(myMap, 'valueOfMyStringValue')}">YEAH!</span>
还是直接在Map
上调用Map#containsKey
方法?
Or call Map#containsKey
method directly on Map
?
<span th:if="${myMap.containsKey('valueOfMyStringValue')}">YEAH!</span>