Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for that map is containg the particular key using thymleaf

Tags:

thymeleaf

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>
like image 241
henrycharles Avatar asked Oct 25 '25 21:10

henrycharles


1 Answers

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>
like image 147
michal.kreuzman Avatar answered Oct 29 '25 20:10

michal.kreuzman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!