thymeleaf 页面取值
标签内取值
<input type="hidden" id="noteId" th:value="${note.id}"/>
标签外取值
<span>[[${userInfo.nickName}]]</span>
switch 判断
<p> <b>推荐</b> <span th:switch="${note.isRecommend}"> <span th:case="1">是</span> <span th:case="0">否</span> </span> </p>
if判断
<img th:if="${userInfo.headImageUrl} != null" th:src="${userInfo.headImageUrl}" width="42" height="42" alt="" class="fl img_editor"> <img th:if="${userInfo.headImageUrl} == null" th:src="@{/community/images/photo.png}" width="42" height="42" alt="" class="fl img_editor">
日期格式化
<span class="fl time">[[${#dates.format(note.createDate, 'yyyy-MM-dd HH:mm')}]]</span>
list 遍历
<div class="con_bottom" th:each="noteComment : ${noteCommentList}"> <div class="clearfix critic_box"> <img th:if="${noteComment.headImageUrl} != null" th:src="${noteComment.headImageUrl}" width="42" height="42" alt="" class="fl"> <img th:if="${noteComment.headImageUrl} == null" th:src="@{/community/images/photo.png}" width="42" height="42" alt="" class="fl"> <div class="fr r_critic clearfix replyBox"> <input type="hidden" id="commentId" th:value="${noteComment.id}"/> <input type="hidden" id="private" th:value="-1"/> <div class="critic clearfix"> <span class="fl critic_name">[[${noteComment.nickName}]]</span> <a class="fr critic_pic"> <span>[[${noteComment.praiseNum}]]<img th:src="@{/community/images/icon_zan.png}" width="25" height="25" alt=""></span> <span>[[${noteComment.commentNum}]]<img th:src="@{/community/images/icon_pinglun.png}" width="25" height="25" alt=""></span> </a> </div> <p class="fl">[[${noteComment.content}]]</p> <div class="replytime clearfix fl"> <span class="fl r_time">[[${#dates.format(noteComment.createDate, 'yyyy-MM-dd HH:mm')}]]</span> <!--<span class="fr reply">回复</span>--> </div> </div> <p class="showreply">查看更多</p> </div> </div>
其中:
th:each属性用于迭代循环,语法:th:each=“obj,iterStat:${objList}”
迭代对象可以是Java.util.List,java.util.Map,数组等;
iterStat称作状态变量,属性有:
index:当前迭代对象的index(从0开始计算)
count: 当前迭代对象的index(从1开始计算)
size:被迭代对象的大小
current:当前迭代变量
even/odd:布尔值,当前循环是否是偶数/奇数(从0开始计算)
first:布尔值,当前循环是否是第一个
last:布尔值,当前循环是否是最后一个
注:以上为使用过程中遇到的,欢迎指正