【Thymeleaf】 循环固定次数/循环次数由变量控制

【Thymeleaf】 循环固定次数/循环次数由变量控制

前言 Thymeleaf 3.0 循环5次 输出5个li: <ul> <li th:each="index:${#numbers.sequence(1, 5)}" > [(${index})]. some thing </li> </ul> 输出结果: <ul> <li> 1. som

前言

Thymeleaf 3.0

循环5次

输出5个li:

<ul>
	<li th:each="index:${#numbers.sequence(1, 5)}" >
		[(${index})]. some thing
	</li>
</ul>

输出结果:

<ul>
	<li>
		1. some thing
	</li>
	<li>
		2. some thing
	</li>
	<li>
		3. some thing
	</li>
	<li>
		4. some thing
	</li>
	<li>
		5. some thing
	</li>
</ul>

循环次数由变量控制

输出5个li:

<ul th:with="liSize=5">
	<li th:each="index : ${#numbers.sequence(1, liSize)}" >
		[(${index})]. some thing
	</li>
</ul>

输出结果:

<ul>
	<li>
		1. some thing
	</li>
	<li>
		2. some thing
	</li>
	<li>
		3. some thing
	</li>
	<li>
		4. some thing
	</li>
	<li>
		5. some thing
	</li>
</ul>

LICENSED UNDER CC BY-NC-SA 4.0