Thymeleaf 如何去除重复标签
Thymeleaf how to remove duplicate tags
在 STS 和文件中创建了示例 spring 引导项目,如下所示:
templetes\fragments\layout.html:
<!DOCTYPE html>
<html>
<head>
<title layout:title-pattern="$DECORATOR_TITLE - $CONTENT_TITLE">Project Title</title>
<link th:replace="/fragments/style"/>
</head>
<body>
<div th:replace="/fragments/header"></div>
<div class="container" style="margin-top:80px;">
<div layout:fragment="content"></div>
</div>
<div th:replace="/fragments/footer"></div>
<div th:replace="/fragments/js"></div>
</body>
</html>
templetes\fragments\style.html:
<!DOCTYPE html>
<link rel="stylesheet" th:href="@{/webjars/bootstrap/3.3.5/css/bootstrap.min.css}"/>
templetes\fragments\js.html:
<!DOCTYPE html>
<script th:src="@{/webjars/jquery/2.1.4/jquery.min.js}"></script>
templetes\fragments\header.html:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<p class="navbar-text">Project Header</p>
</div>
</nav>
</body>
</html>
templetes\fragments\footer.html:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-bottom">
<div class="container">
<p class="navbar-text">Project Footer</p>
</div>
</nav>
</body>
</html>
templetes\index.html:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="fragments/layout">
<head>
<title>Page Title</title>
</head>
<body>
<div layout:fragment="content">
Page Content
</div>
</body>
</html>
虽然浏览器正确呈现页面,但生成的源重复标记为:
<!DOCTYPE html>
<html>
<head>
<title>Project Title - Page Title</title>
<link rel="stylesheet" href="/webjars/bootstrap/3.3.5/css/bootstrap.min.css" />
</head>
<body>
<html>
<head>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<p class="navbar-text">Project Header</p>
</div>
</nav>
</body>
</html>
<div class="container" style="margin-top:80px;">
<div>
Page Content
</div>
</div>
<html>
<head>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-bottom">
<div class="container">
<p class="navbar-text">Project Footer</p>
</div>
</nav>
</body>
</html>
<script src="/webjars/jquery/2.1.4/jquery.min.js"></script>
</body>
</html>
请指导我删除这些多余的标签。
谢谢
据我所知,'duplicate' 标签已经在您的页眉和页脚模板中了。只需删除它们(它们实际上应该只是 html 个片段)就可以了!
在 STS 和文件中创建了示例 spring 引导项目,如下所示:
templetes\fragments\layout.html:
<!DOCTYPE html>
<html>
<head>
<title layout:title-pattern="$DECORATOR_TITLE - $CONTENT_TITLE">Project Title</title>
<link th:replace="/fragments/style"/>
</head>
<body>
<div th:replace="/fragments/header"></div>
<div class="container" style="margin-top:80px;">
<div layout:fragment="content"></div>
</div>
<div th:replace="/fragments/footer"></div>
<div th:replace="/fragments/js"></div>
</body>
</html>
templetes\fragments\style.html:
<!DOCTYPE html>
<link rel="stylesheet" th:href="@{/webjars/bootstrap/3.3.5/css/bootstrap.min.css}"/>
templetes\fragments\js.html:
<!DOCTYPE html>
<script th:src="@{/webjars/jquery/2.1.4/jquery.min.js}"></script>
templetes\fragments\header.html:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<p class="navbar-text">Project Header</p>
</div>
</nav>
</body>
</html>
templetes\fragments\footer.html:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-bottom">
<div class="container">
<p class="navbar-text">Project Footer</p>
</div>
</nav>
</body>
</html>
templetes\index.html:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="fragments/layout">
<head>
<title>Page Title</title>
</head>
<body>
<div layout:fragment="content">
Page Content
</div>
</body>
</html>
虽然浏览器正确呈现页面,但生成的源重复标记为:
<!DOCTYPE html>
<html>
<head>
<title>Project Title - Page Title</title>
<link rel="stylesheet" href="/webjars/bootstrap/3.3.5/css/bootstrap.min.css" />
</head>
<body>
<html>
<head>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<p class="navbar-text">Project Header</p>
</div>
</nav>
</body>
</html>
<div class="container" style="margin-top:80px;">
<div>
Page Content
</div>
</div>
<html>
<head>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-bottom">
<div class="container">
<p class="navbar-text">Project Footer</p>
</div>
</nav>
</body>
</html>
<script src="/webjars/jquery/2.1.4/jquery.min.js"></script>
</body>
</html>
请指导我删除这些多余的标签。 谢谢
据我所知,'duplicate' 标签已经在您的页眉和页脚模板中了。只需删除它们(它们实际上应该只是 html 个片段)就可以了!