@GetMapping("/p5")
public void p5(Model model) {
}
创建templates/comonent/p5.html
这个用来存储我们的组件,代码如下:
th:fragment
指定组件的名称组件一个id
,后面通过id使用组件<!DOCTYPE html>
<html lang="en" xmlns:th="<http://www.thymeleaf.org>">
<head>
</head>
<div th:fragment="header">
<div style="height: 100px; background-color: gold">
<h1>I'am Header</h1>
</div>
</div>
<div th:fragment="footer">
<div style="height: 100px; background-color: cornflowerblue">
<h1>I'am Footer</h1>
</div>
</div>
<div id="body">
<div style="height: 100px; background-color: yellowgreen">
<h1>I'am Body</h1>
</div>
</div>
</html>
创建templates/p5.html
用来最为最终的渲染
th:insert="component/p5::header"
将这个组件插入
到div当中去th:insert="component/p5::#body"
,通过id寻找组件,并插入
到div当中去th:replace="component/p5::footer"
,将组件替换
掉div标签<!DOCTYPE html>
<html lang="en" xmlns:th="<http://www.thymeleaf.org>">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div th:insert="component/p5::header"></div>
<div th:insert="component/p5::#body"></div>
<div th:replace="component/p5::footer"></div>
</body>
</html>