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:布尔值,当前循环是否是最后一个

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


相关文章
|
7月前
|
Java API 数据库
thymeleaf 中 通用的分页方法
thymeleaf 中 通用的分页方法
|
7月前
|
JavaScript
thymeleaf页面取值与js取值
thymeleaf页面取值与js取值
|
7月前
|
Java
thymeleaf的each标签遍历取值
thymeleaf的each标签遍历取值
|
7月前
|
JavaScript 前端开发
Thymeleaf属性值详解
Thymeleaf属性值详解
|
7月前
Thymeleaf显示表格
Thymeleaf显示表格
thymeleaf 的 th:each 标签示例
thymeleaf 的 th:each 标签示例
【Thymeleaf】thymeleaf中给input的value属性设置值
【Thymeleaf】thymeleaf中给input的value属性设置值
477 0
|
JSON 前端开发 JavaScript
Spring MVC 实战:响应字段默认值设置
前言 到今天为止,相信大家开发 Web 项目应该都是前后端分离了吧?前后端分离中一般会使用 json 作为前后端的数据交换格式。json 中可以包含数值、字符串、json 对象、数组等等。
288 0
Spring MVC 实战:响应字段默认值设置
|
Java
Thymeleaf的常用属性和标准表达式
Thymeleaf的常用属性和标准表达式
140 0
|
JavaScript 数据可视化 Java
spring boot 用js实现上传文件(包含其他字段)显示进度
spring boot 用js实现上传文件(包含其他字段)显示进度
221 0
spring boot 用js实现上传文件(包含其他字段)显示进度

热门文章

最新文章