日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Springboot的thymeleaf常用属性

發布時間:2023/12/31 javascript 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Springboot的thymeleaf常用属性 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • th:text? ? ? th:utext? 設置元素中的文本內容

? ? ? th:text對特殊字符進行轉義,作為純文本標簽,等價于內聯方式[[${ }]]

? <!-- ?使用表達式 -->
? ?<p th:text="${name}">Welcome to Thymeleaf!</p>
? <!-- ?使用內聯方式 -->
? ? <p>[[${name}]]Welcome to Thymeleaf!</p>


? ? ? th:utext? ?對特殊字符不進行轉義,可以顯示出字符的作用,等價于內聯方式[(${ })]

? ? ?<!-- ?使用表達式 -->
? ? <p th:utext="${name}">Welcome to Thymeleaf!</p>
? ? ? <!-- ?使用內聯方式 -->
? ?<p>[(${name})]Welcome to Thymeleaf!</p>

  • th:html的原生屬性

? ?<div id=test title="這是一個div" th:id="${id}" th:title="${title}">div</div>

  • th:if、th:unless、th:switch、th:case? 條件判斷

? ? <!--th:if、th:unless、th:switch、th:case-->
? ? <p th:if="${age>=18}">成年</p>
? ? <p th:unless="${age<18}">成年</p>
? ? <p th:switch="${role}">
? ? ? ? <span th:case="admin">管理員</span>
? ? ? ? <span th:case="teacher">老師</span>
? ? ? ? <span th:case="student">學生</span>
? ? ? ? <span th:case="*">其他</span>
? ? </p>

  • th:each? ? ? ? ?循環

? ? <!--th:each-->
? ? <ul>
? ? ? ? <!--<li th:each="name:${names}" th:text="${name}"></li>-->
? ? ? ? <li th:each="name:${names}">[[${name}]]</li>
? ? </ul>

  • th:object、th:field? ? ? ?用于表單數據對象的綁定,將表單綁定到Controller的一個JavaBean參數,常與th:field一起使用,需要和*{}選擇表達式配合使用? ?

? ? <!--th:object、th:field-->
? ? <h3>修改用戶信息</h3>
? ? <form action="modify" method="post" th:object="${user}">
? ? ? ? 編號:<input type="text" th:field="*{id}" readonly> <br>
? ? ? ? 姓名:<input type="text" th:field="*{name}"> <br>
? ? ? ? 年齡:<input type="text" th:field="*{age}"> <br>
? ? ? ? <input type="submit" value="修改">
? ? </form>

  • th:fragment?聲明代碼片段,常用于頁面頭部和尾部的引入

? ? <!--th:fragment-->
? ? <header th:fragment="head">
? ? ? ? 這是頁面的頭部,導航
? ? </header>

  • th:include、th:insert、th:replace??引入代碼片段,類似于jsp:include碼片段

? ? <!--th:include、th:insert、th:replace-->
? ? <!--引入templates/include/header.html中的frament=head的代碼片段-->
? ? <div th:include="include/header::head"></div>
? ? <div th:insert="include/footer::copy"></div>
? ? <div th:replace="include/header::head"></div>

th:include 保留自己的標簽,不要th:frament的標簽(Thymeleaf 3.0中不推薦使用)
th:insert 保留自己的標簽,保留th:frament的標簽
th:replace 不要自己的標簽,保留th:frament的標簽

總結

以上是生活随笔為你收集整理的Springboot的thymeleaf常用属性的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。