javascript
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常用属性的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 国债逆回购购买步骤 有以下三步
- 下一篇: idr是什么货币