#author("2019-11-15T14:00:46+08:00","default:Admin","Admin") Thymeleaf

在Thymeleaf 中,我们可以使用th:fragment属性来定义一个模板。

我们可以新建一个简单的页尾模板,如:/WEB-INF/templates/footer.html,内容如下:

<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
  <body>
    <div th:fragment="copyright">
      © 2016 xxx
    </div>
  </body>
</html>

上面定义了一个叫做copyright的片段,接着我们可以使用th:include或者th:replace属性来使用它:

<body>
  ...
  <div th:include="footer :: copyright"></div> 
</body>

模板片段可以被包含在任意th:*属性中,并且可以使用目标页面中的上下文变量。

th:include 和 th:replace区别

th:include 是加载模板的内容,而th:replace则会替换当前标签为模板中的标签

例如如下模板:

<footer th:fragment="copy"> 
&copy; 2016
</footer>

我们通过th:include 和 th:replace来加载模板

<body> 
  <div th:include="footer :: copy"></div>
  <div th:replace="footer :: copy"></div>
</body>

返回的HTML如下:

<body> 
   <div> &copy; 2016 </div> 
  <footer>&copy; 2016 </footer> 
</body>


中古車買取実績No.1ガリバー

コメント:



(画像の文字列を入力して下さい)

トップ   編集 凍結 差分 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2019/12/02 (月) 12:42:55 (1628d)

PCpዾyǗlgĂ܂}WŔ܂z 萔O~ył񂫁z Yahoo yV NTT-X Store

z[y[W ̃NWbgJ[h COiq ӂ邳Ɣ[ COsیI COze