thymeleaf标签

模板布局

th:fragment
th:insert
th:replace
th:remove
  • th:fragment=“body” 模板布局:指会经常被别人引用的一部分,为他打上标签,以便引用

    <div th:fragment="copy">
          &copy; 2011 The Good Thymes Virtual Grocery
    </div>
    
  • th:insert=“commons/commons::body” 在指定部分引用模板布局

  • th:replace=“commons/commons::body” 在指定部分引用模板布局

    <body>
         ...     <div th:insert="~{footer :: copy}"></div>     ...
    </body>
    
  • th:remove=“tag” 移除当前标签或子标签

    <!--tag:删除自己,但不删除所有子项-->
    <div class="hint" th:remove="tag">
        <p>tag<span> $</span></p>
    </div>
    
  • 学习网址

表单提交

th:action
  • th:action="@{/aBcd/eee}" 表单提交地址,相当于action

解析数据

th:object
th:field
th:value
th:text
th:utext
  • th:object="${xxForm}" 解析后端传前端的数据使用
  • th:field="*{name}"
    <div th:object="${userInfoForm}">                                                                       
         <p>name: <span th:text="*{name}">XXXX</span>.</p>
         <input th:field="*{name}"/>    
    </div>
    
  • th:value="${intermediary.piCode}" 解析后端传前端的数据使用
    <input th:value="${userInfoForm.name}"/>
    
  • th:field="*{name}" 等同于th:name和th:value,而 th:value="${intermediary.piCode}" 只为value
    th:field="*{name}" 在前面要有使用th:object才可以使用

  • th:text="${message}" 文本替换
  • th:utext="${message}" 支持html的文本替换
    当前日期:<span th:text="${dt}"></span>超出平均值 <span th:text="${ratioPercent}+'%'"></span>
    

emmm

  • th:checked=“true” 复选框选中

    <input type="checkbox" name="typeCustomer" value="1" th:checked="*{customerType} eq '1'"/>
    
  • th:if="${code}"

    <span th:if="*{code != null}" th:text="*{code}"></span>
    
    <!--if属性结果为 true,模板会进行显示-->
    <p th:if="true">th:if="true"</p>
    <!--if属性结果为 false,模板不会进行显示-->
    <p th:if="false">th:if="false"</p>
    
    
  • th:each=“intermediary:${intermediaryList}” 遍历

    <tr th:each="user : ${userList}">
      <td th:text="${user.name}">xxx</td>
    </tr>
    
  • 学习网址

th:block

  • 块标签(空标签),标签本身不显示
    <th:block th:if='${1!=1}'>
    	<button class="btn btn-default" data-toggle="modal" data-target="#myModal">
    	   <i class="fa fa-plus"></i> 新增2不显示
    	</button>
    </th:block>
    
  • th:classappend=“big-big” 在不改变标签内class属性的前提下,添加某class样式
    <div class="big-box" th:classappend="${captchaEnabled == false} ? 'm-t': ''">111</div>
    
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值