th:href="@{值}"

<link href="http://cdn.jsdelivr.net/webjars/bootstrap/3.3.7/css/bootstrap.min.css"
          th:href="@{/webjars/bootstrap/3.3.7/css/bootstrap.min.css}"
这里th:href就是将超连接的值http://xxx/bootstrap.min.css  给重定义成"/webjars/bootstrap/3.3.7/css/bootstrap.min.css"了
thymeleaf
<script src="http://cdn.jsdelivr.net/webjars/jquery/3.2.1/jquery.min.js"
            th:src="@{/webjars/jquery/3.2.1/jquery.min.js}"></script>

th:fragment & th:replace

th:fragment定义的片段,在需要的地方,可以用th:include或者th:replace进行带入
先在header.html 里定义好片断
thymeleaf
然后在layout.html里通过 th:replace 引入片段
<div th:replace="fragments/header :: header">
This content is only used for static prototyping purposes
</div

页面使用布局器layout:decorate

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layouts/layout}">

需要在页面的最上方使用layout:decorate声明布局页面的位置 本例是在layouts目录下的layout.html

thymeleaf

 

相关文章: