如何使用 thymleaf 检查该地图是否包含特定密钥 [英] How to check for that map is containg the particular key using thymleaf

查看:27
本文介绍了如何使用 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>

这篇关于如何使用 thymleaf 检查该地图是否包含特定密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆