Thymeleaf iterating over a list

Viewed 194

I want to iterate over a list using thymeleaf. My code looks like this:

<ol th:each="test: ${tests}">
    <li th:text="${test.toString()}"></li>
</ol>

At this moment, tests Set contains 2 elements, which have a toString() representation, respectively test1 and test2

My output in html looks like this:

1.test1
1.test2

I am wondering why do both of them have the number 1, instead of 1 and 2?

1 Answers

You are creating an ordered list for each item instead of listitems.

This should work:

<ol>
    <li th:each="test: ${tests}" th:text="${test.toString()}"></li>
</ol>
Related