前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >thymeleaf 页面取值常用

thymeleaf 页面取值常用

作者头像
六月的雨在Tencent
发布2024-03-28 20:01:49
1230
发布2024-03-28 20:01:49
举报
文章被收录于专栏:CSDNCSDN

标签内取值

代码语言:javascript
复制
<input type="hidden" id="noteId" th:value="${note.id}"/>

标签外取值

代码语言:javascript
复制
<span>[[${userInfo.nickName}]]</span>

switch 判断

代码语言:javascript
复制
<p>
	<b>推荐</b>
	<span th:switch="${note.isRecommend}">
	<span th:case="1">是</span>
	<span th:case="0">否</span>
	</span>
</p>

if判断

代码语言:javascript
复制
<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">

日期格式化

代码语言:javascript
复制
<span class="fl time">[[${#dates.format(note.createDate, 'yyyy-MM-dd HH:mm')}]]</span>

list 遍历

代码语言:javascript
复制
<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:布尔值,当前循环是否是最后一个

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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2024-03-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 标签内取值
  • 标签外取值
  • switch 判断
  • if判断
  • 日期格式化
  • list 遍历
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档