Domanda

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>
È stato utile?

Soluzione

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.

Did you tried use constant String as key?

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

Or call Map#containsKey method directly on Map?

<span th:if="${myMap.containsKey('valueOfMyStringValue')}">YEAH!</span>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top