Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop through Map in Thymeleaf

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.

like image 695
phil.e.b Avatar asked Apr 17 '14 22:04

phil.e.b


People also ask

How do you iterate through a list in Thymeleaf?

In Thymeleaf, iteration is achieved by using the th:each attribute. One of the interesting things about this attribute is that it will accept and iterate over some different data types, such as: objects implementing java. util.

What is th block Thymeleaf?

th:block is a Thymeleaf element rather than an attribute, and it has the general syntax: 1 2 3. <th:block> <!-- Your HTML code --> </th:block> th:block allows you to apply the same Thymeleaf attribute, like th:if or th:each to a block of code.


1 Answers

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.

like image 61
phil.e.b Avatar answered Oct 15 '22 06:10

phil.e.b