您的位置:首页 > Web前端 > JavaScript

thymeleaf模板引入公共js或者引入片段html

2017-08-07 00:00 393 查看
1.引入片段html

#定义引入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="copy">
<p>测试文字</p>
</div>
</body>
</html>

#引用页面
<body>
<div th:include="test :: copy"></div>
</body>

2.引入公共的js

在templates下新建个common.html:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta charset="UTF-8"/>
<link th:href="@{/plugin/jquery-easyui-1.5.2/themes/icon.css}" rel="stylesheet"/>
<link th:href="@{/plugin/jquery-easyui-1.5.2/themes/default/easyui.css}" rel="stylesheet"/>
<script th:src="@{/plugin/jquery/jquery-3.2.1.js}"></script>
</head>
</html>

在其他页面使用:
<head th:include="common">
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: