Thymeleaf 模板 js和css引入的方式

Thymeleaf是现代化服务器端的Java模板引擎,不同与JSP和FreeMarker,Thymeleaf的语法更加接近HTML,并且也有不错的扩展性。详细资料可以浏览官网。本文主要介绍Thymeleaf模板的使用说明。

模板(template fragments)

定义和引用模板

日常开发中,我们经常会将导航栏,页尾,菜单等部分提取成模板供其它页面使用。

在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>

参考链接:https://www.cnblogs.com/lazio10000/p/5603955.html 

猜你喜欢

转载自my.oschina.net/qimhkaiyuan/blog/1798381