【发布时间】:2016-08-08 08:45:02
【问题描述】:
我最近在春季开始使用 thymeleaf 模板引擎。我想要实现的是 - 如果我的控制器是这样的
@RequestMapping(value="/", method=RequestMethod.GET)
public String index() {
return "homePage";
}
然后我想在 homePage.html 中编写 HTML 代码,而不需要完整的 HTML 定义,如头部、标题、正文等。
<div>This is home page content</div>
不想这样写在 homePage.html 中。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" >
<head>
<title>Spring MVC Example</title>
</head>
<body>
<div th:include="fragments/header::head"></div>
<div>This is home page content</div>
<div th:include="fragments/footer::foot"></div>
</body>
我更喜欢为页眉片段、控制器中的内容和页脚片段中的页脚提供头部部分。
所以总的来说 - 我怎么能做到这一点:
/fragment/header.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" >
<head>
<title>Spring MVC Example</title>
</head>
<body>
/home.html
<div>This is home page content</div>
(这个抛出错误)
/fragment/footer.html
</body>
</html>
注意:我已经看过这些例子
【问题讨论】:
-
您能否粘贴包含页脚时出现的错误?