How to loop through Map in Thymeleaf

phil.e.b picture phil.e.b · Apr 18, 2014 · Viewed 56.4k times · Source

I am trying to understand how to loop through all entries in a Map in Thymeleaf. I have a domain object being processed by Thymeleaf that contains a Map.

How do I loop through the keys and fetch the values ?

Thanks.

Answer

phil.e.b picture phil.e.b · Apr 18, 2014

Nevermind... I found it...

<tr th:each="instance : ${analysis.instanceMap}">
    <td th:text="${instance.key}">keyvalue</td>
    <td th:text="${instance.value.numOfData}">num</td>
</tr>

Thanks.