Search code examples
javathymeleaf

How to iterate through a list of arrays using thymeleaf


I'm trying to populate a table in my template with a list of object arrays

List<Object[]> list

Every object array of this list has a fixed length and it's the same for all.

I need something like this

<table>
    <tr th:each="obArr:${list}">
        <td th:text="${obArr[0]}"></td>
        <td th:text="${obArr[1]}"></td>
        <td th:text="${obArr[2]}"></td>
    </tr>
</table>

Is this possible using thymeleaf, or should I try a different approach?


Solution

  • Yes, it's possible.

    You can find some helpful examples here: http://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.html#listing-seed-starter-data