th:标签
https://blog.csdn.net/xxb5502296/article/details/78319898(挺全的)
https://blog.csdn.net/qq_43279637/article/details/86406836
http://www.cnblogs.com/vinphy/p/4674247.html
https://blog.csdn.net/qwlzxx/article/details/70976509
th:text把表達式對應的值代替標簽內的文本。(<p th:text="#{home.welcome}">welcome</p>)
th:utext顯示非轉義文本。(自動解析文本中的html標簽并渲染頁面)
th:object在父標簽選擇對象,子標簽使用*{…}選擇表達式選取值。沒有選擇對象,那子標簽使用選擇表達式和${…}變量表達式是一樣的效果。同時即使選擇了對象,子標簽仍然可以使用變量表達式。
<div th:object="${session.user}" >
<p th:text="*{fisrtName}">firstname</p>
<p th:text="${session.user.lastName}">lastname</p>
</div>
th:href修改a標簽的href屬性,使用@{…}URL表達式展示路徑。URL參數也可以被寫進表達式。
<a href="list.html" th:href="@{/users/list(id=${o.id},name=${o.name})}">查詢</a>
th:with在當前標簽范圍內,創建一個本地變量(local variable),并添加到上下文的變量map。
<div th:with="name=${user.name},nickname=${name}+'用戶'">...
th:attr設置或者修改標簽屬性(不推薦),推薦使用th:value、th:action、th:class,相當于th:attr=”value=…”、th:attr=”action=…”等等。
<input type="submit" value="submit" th:attr="value=#{submit.text}" />
th:classappend、th:styleappend、th:attrappend、th:attrprepend屬性前或者后添加屬性值。
<tr class="r" th:attrappend="class=' odd'">
<tr class="r" th:classapend="'odd'">
th:checked、th:disabled、th:selected根據判斷條件結果來決定是否給該checked等屬性設定固定值。
<input type="checkbox" th:checked="${user.active}"/>
th:assert斷言,支持逗號分隔的多條件。
<div th:assert="${var1},${var2}==2,#lists.isEmpty(${list})">
th:remove被處理時會被刪除,支持參數all,tag,body,all-but-first,none。顧名思義,舉例all-but-first應用場景。
<tbody th:remove="all-but-first">
<tr th:each="prod:${prods}">...</tr>
<tr><td>示例數據</td></tr>
</tbody>
th:if判斷是否需要展示此標簽,當null、0、’0’、’false’、’off’、’no’時為false,否則為true。
<div th:if="${user.isAdmin()}">...
th:unless與th:if相反
th:switch、th:case同java中的switch、case用法
<div th:switch="${user.role}">
<p th:case="'admin'">administrator</p>
<p th:case="*">other</p>
</div>
th:each迭代,支持Iterable、Map(迭代局部變量為Map.Entry)、數組、包含對象本身的單值對象。
<tr th:each="prod : ${prods}">
<td th:text="${prod.name}">..</td>
</tr>
${prods}是迭代變量,prod是本地變量(local variable),上例中在tr范圍內有效。
th:each迭代狀態變量,支持獲取參數如index、count、size、current、even/odd、fisrt、last。
<tr th:each="prod,iterStat : ${prods}" th:class="${iterStat.odd}?'odd'">
<td th:text="${iterStat.current.name}">...</td>
</tr>
隱式支持迭代局部變量+Stat作為本地變量,上例中不聲明iterStat可直接使用prodStat。
th:fragment、th:include、th:replace引入或替換模板內容,支持引入其他模板文件的部分templatename::domselector(支持XPath語法或者css選擇器)、templatename::fragmentname,也支持引入整個模板templatename或者本模板內的部分::domselector
<div th:include="footer::#{footer.admin}">
----------分割線----------
<div th:fragment="#{footer.admin}">
copyright 2017
</div>
th:replace不同于th:include,它將引用模板的整個dom替換當前dom。th:include是將引用模板的dom下子元素引入到當前dom內。
fragment可引入類函數機制,同時函數參數可以不聲明即使用。
<div th:fragment="frag(var1,var2)">
<div th:include="::flag(var1=${var1},var2=${var2})">
th:block作為屬性容器,處理屬性時會消失。
<table>
<th:block th:each="r:${rs}">
<tr><td th:text="${r.name}">1</td></tr>
</th:block>
</table>
th:inline內聯,即把表達式直接寫進html文本而不是屬性,支持模式text、javascript、none。
<!-- 同 <p th:text="'hello,'+${session.user.name}+'!'">abc</p> -->
<p th:inline="text">hello,[[${session.user.name}]]!</p>
<!-- 利用javascript注釋/*..*/,保證靜態或被thymeleaf處理后都能正確展示頁面 -->
<script th:inline="javascript">
var user = /*[[${session.user}]]*/ null;
</script>
data-{prefix}-{name}對html5更友好的語法,等同于{prefix}:{name}
<td data-th-text="${user.name}">...</td>
th:field作用于input、select、textarea,th:field和th:object聯用,
<input type="text" th:field="*{date1}" />——id、name為date1,value綁定date1屬性值
<ul>
<li th:each="feat: ${allFeats}">
<input type="checkbox" th:field="*{feats}" th:value="${feat}">——id為feats1類推,name為feats,value為當前遍歷feat的值。feats屬性的值所在input會加上checked屬性。
<lable th:for="${#ids.prev('feats')}"——for為feats字段當前遍歷序列中最后一個id
th:text="#{${'feature.'+feat}}">abc</label>
</li>
</ul>
<select th:field="*{type}">
<option th:each="type:${types}"
th:value="${type}"
th:text="#${'type.'+type}}">選項</option>
</select>
總結
- 上一篇: Flask框架(七)
- 下一篇: 老花镜有度数吗(老花镜戴的时间越长度数越