java Thymeleaf:默认情况下创建自定义节。html
以前我只使用JSP和Apache Tiles,现在我正试图第一次创建Thymeleaf模板。我面临的问题是,我不知道如何在默认设置中插入自定义页眉、页脚和其他部分。html。下面是代码示例
默认。html:
<!DOCTYPE html>
<html lang="en"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta charset="UTF-8"/>
<title>Default template</title>
<link rel="stylesheet" type="text/css" href="../static/css/app.css" th:href="@{/css/app.css}"/>
<link rel="stylesheet" type="text/css" href="../static/css/bootstrap.css" th:href="@{/css/bootstrap.css}"/>
<link rel="stylesheet" type="text/css" href="../static/css/myCss.css" th:href="@{/css/myCss.css}"/>
</head>
<body>
<header id="header" layout:fragment="header">
HEADER
</header>
<section id="sidemenu" layout:fragment="sideMenu">
SIDE_MENU
</section>
<section id="site-content" layout:fragment="siteContent"></section>
<footer id="footer" layout:fragment="footerTemplate"></footer>
</body>
</html>
默认情况下。html我有“siteContent”,用于插入应用程序的所有html文件,以及“header”、“sideMenu”和“footer”部分,这些部分必须在单独的相应html文件(模板)中实现,并插入到默认设置中。html
索引。html:
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="default">
<head>
<title>Index</title>
</head>
<body>
<div layout:fragment="siteContent">
<h1>Hello world!</h1>
</div>
</body>
</html>
页脚。html:
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<title>Footer Template</title>
</head>
<body>
<div layout:fragment="footer">
Copyright © 2017
</div>
</body>
</html>
这是页脚的一个例子
SiteContent区域运行良好。Footer的“版权©2017”应导入默认版本。html的页脚区域,但它没有
# 1 楼答案
解决办法是:我应该使用 '页脚 id="footer" layout:include="footerTemplate"' instead of 'footer id="footer" layout:fragment="footerTemplate"'
顺便说一句,在thymeleaf's website上列出的例子从来都不起作用,但没有正确的决定