Thymeleaf is a modern server-side Java template engine. Unlike JSP and FreeMarker, Thymeleaf's syntax is closer to HTML, and it also has good extensibility. Details can be found on the official website . This article mainly introduces the instructions for using the Thymeleaf template.
template (template fragments)
Defining and referencing templates
In daily development, we often extract the navigation bar, footer, menu and other parts into templates for other pages to use.
In Thymeleaf, we can use th:fragment
attributes to define a template.
We can create a simple footer template, such as: /WEB-INF/templates/footer.html, the content is as follows:
<!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="copyright">
© 2016 xxx
</div>
</body>
</html>
The above defines a copyright
fragment called , which we can then use with the th:include
or th:replace
attribute:
<body>
...
<div th:include="footer :: copyright"></div>
</body>
Reference link: https://www.cnblogs.com/lazio10000/p/5603955.html