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

前言

  • 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>
    原文作者:sayyy
    原文地址: https://blog.csdn.net/sayyy/article/details/90036181
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞