zl程序教程

您现在的位置是:首页 >  Java

当前栏目

thymeleaf th:text拼接及循环

2023-02-18 16:31:17 时间

我们在使用thymeleaf的时候,有时候需要循环并且拼接,怎么办呢?

先来查看效果:

后端返回:

mmap.put("startEndSizes", purchaseDetail.getStartEndSizeList());

返回的是一个List

在页面上使用th:each来进行循环。字符串拼接使用+.如下图:

<div>
    <div class="form-group" th:each="startEndSize:${startEndSizes}">
        <label class="col-sm-3 control-label" th:text="'起始尺寸-'+${startEndSize.sizeName}">:</label>
        <div class="col-sm-8">
           <!-- <label  th:text="${startEndSize.sizeName}"></label>-->
            <input name="purchaseNum" th:value="${startEndSize.size}"  class="form-control" type="text" >
        </div>
    </div>
</div>