Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to loop through 1 to 5 in thymeleaf?

Tags:

thymeleaf

I want to loop through 1 to 5 in the thymeleaf, similar to jsp code:

<c: forEach begin = "1" end = "5" varStatus = "V"> </ c: forEach>.
like image 404
花和尚 Avatar asked Feb 14 '17 01:02

花和尚


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.

How do you break the loop in Thymeleaf?

The best solution would be the put this logic in the controller and put the first product of type 'T' in a separate attribute. If that's not possible, another solution would be to write a Thymeleaf extension (or if using Spring a bean) that does this.

What is th block?

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

<th:block th:each="i: ${#numbers.sequence(1, 5)}"></th:block>
like image 140
Metroids Avatar answered Oct 12 '22 06:10

Metroids