Cómo hacer un bucle a través del mapa en Thymeleaf


Estoy tratando de entender cómo recorrer todas las entradas de un mapa en Thymeleaf. Thymeleaf está procesando un objeto de dominio que contiene un mapa.

¿Cómo hago un bucle entre las teclas y obtengo los valores ?

Gracias.

Author: phil.e.b, 2014-04-18

2 answers

No importa... Lo encontré...

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

Gracias.

 64
Author: phil.e.b,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-17 09:42:37

En caso de que tenga una lista como valor. Por ejemplo, cuando tiene un mapa con la clave como categoría y el valor como una lista de elementos pertenecientes a esa categoría, puede usar esto:

<table>
    <tr th:each="element : ${catsAndItems}">
        <td th:text="${element.key}">keyvalue</td>
        <table>
            <tr th:each="anews : ${element.value}">
                <td th:text="${anews.title}">Some name</td>
                <td th:text="${anews.description}">Some name</td>
                <td th:text="${anews.url}">Some name</td>
                <td th:text="${anews.logo}">Some name</td>
                <td th:text="${anews.collectionDate}">Some name</td>
            </tr>
        </table>
    </tr>
</table>
 16
Author: ACV,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-17 11:47:59