<table border="1">
<tr th:each="skuImage:${skuInfo.skuImageList}">
<td th:text="${skuImage.id}"></td>
<td th:text="${skuImage.imgName}"></td
</tr>
</table>
解释:
th:each="属性值(类2):${ 类1.属性名list}" 获取list集合中的属性值
th:text="${类2.属性名}" 输出属性值
<table>
<!-- <c:foreach items="${arrayList}" var = "arry">-->
<tr th:each="arry,stat: ${arrayList}">
<td th:text="${arry}"></td>
<td th:text="${stat.index}"></td>
</tr>
</table>
解释:循环each标签后添加,stat关键字,stat.index 即是下标,下标从0开始。
-
ThymeLeaf特点:
-
ThymeLeaf与Jsp的比较
-
ThymeLeaf:建立在自然模板上(H5标签),渲染数据的时候,都是一些h5的扩展标签属性。
-
jsp:建立在自然模板上,渲染数据的时候,需要使用JSTL,EL表示式。
-
-
ThymeLeaf与FreeMarker比较
-
ThymeLeaf:建立在自然模板上。
-
FreeMarker:必须先用ftl模板。
-
-
-
ThymeLeaf的使用:
-
现在页面中引入ThymeLeaf的命名空间 (页面开头的html标签替换)
-
在后台存值,前台显示。
-
-
ThymeLeaf标签:
-
输出 <div th:text="${类.属性名}" th:value='123'></div> th:text 表示div显示文本 “${属性.值}”默认是取出request域中的值 th:value 是给标签设置默认值 案例标签就是取出requesty域中的值并显示到页面。
-
循环
-
带索引的循环
-
取session中的值
-
<div th:text="${session.userName}"> </div> "${session.属性名}"
-
引用内嵌页
-
<div th:include="itemInner"/>
-
-
判断
-
三元运算:
-
<td th:text="(${skuImage.id}=='10')?'是10':'不是10'"></td> <td th:text="${类.属性名}==值?'正确的输出结果':'错误的输出结果'">
-
普通判断
-
<td th:if="${skuImage.id}=='10'" th:text="123">123456</td> 如果判断成立,直接输出123,如果没有th:text标签,那么就输出div标签中的123456
-