Which Thymeleaf attribute is used to iterate over a collection?
A)
th:eachB)
th:forC)
th:loopD)
th:repeatAnswer:
A)
th:eachExplanation:
The th:each attribute in Thymeleaf is used to iterate over a collection of items. It works similarly to a for-each loop in Java, allowing you to render a list of elements dynamically.
For example:
<ul>
<li th:each="item : ${items}">[[${item.name}]]</li>
</ul>
In this example, th:each iterates over the items collection and renders each item as a list element.