thymeleaf 布局:装饰器如何工作

Upo*_*pol 5 thymeleaf spring-boot

我在 springboot (1.3.2) - thymeleaf (2.1.4) - thymeleaf 布局方言 (1.3.1) 项目中遇到了一段代码,我正在工作,内容 html 文件包含:

<html xmlns:th="http://www.thymeleaf.org" layout:decorator="layout/sitelayout">
...

<div th:fragment="content" class="container">
....
</div>
Run Code Online (Sandbox Code Playgroud)

sitelayout.html 文件包含:

<div layout:fragment="content">
    <h1>Static content for prototyping purposes only</h1>

    <p>
        This is the layout of the site. The actual content will come from individual views making use of this layout
    </p>
</div>
Run Code Online (Sandbox Code Playgroud)

=================================================== =

我搜索了网络,但找不到足够的有关其工作原理的信息/文档示例。有人能指出我正确的方向吗?

小智 2

我有信息可以回答您有关如何使用此代码的问题。仅供参考,我确实相信代码应该说layout:decorate而不是layout:decorator在 HTML 标记中。

布局方言的基本描述

[...]布局方言使人们能够使用分层方法[...]。Thymeleaf 布局方言使用布局/装饰器模板来设计内容的样式,并且它可以将整个片段元素传递到包含的页面。[...]

参考

Thymeleaf 布局文档

  • 请转至第 4 部分,具体阅读有关 的内容layout:decorate。

Baeldung 使用 Thymeleaf 布局的教程。

希望这可以帮助。