thymeleaf 页面取值常用

本文详细介绍了Thymeleaf模板引擎的各种标签用法,包括取值、条件判断、日期格式化及列表遍历等功能,是理解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:布尔值,当前循环是否是最后一个

注:以上为使用过程中遇到的,欢迎指正

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

csdn565973850

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值