thymeleaf 引入共通静态文件
实现方式有很多,记录一下个人觉得最舒舒服的方式
在templates静态模板下建一个静态的共通片段
common_header.html
代码如下
<!DOCTYPE html>
<!--suppress ALL-->
<html lang="en">
<html xmlns:th="http://www.thymeleaf.org">
<head th:fragment=header(title)>
<title th:text="${title}"></title>
<meta charset="utf-8">
<link th:href="@{common/layer/need/layer.css}" rel="stylesheet"/>
<script th:src="@{common/jquery-2.1.0.js}"></script>
</div>
</head>
<body>
</html>
在需要用到这段共通的地方加入该代码片段
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<!-- common_header 是刚才定义的片段文件名,如有有二级目录需要加上
header('test') 相当于common_header
中定义的th:fragment=header(title) 传入的test会是该页面的title-->
<th:block th:include="common_header :: header('test')" />
</head>
运行页面后