【问题标题】:Spring Boot Thymeleaf Layout Dialect Not WorkingSpring Boot Thymeleaf 布局方言不起作用
【发布时间】:2017-06-21 02:33:50
【问题描述】:

我刚刚创建了一个新的 Spring Boot v1.5 项目,并面临 Thymeleaf 布局方言不起作用的问题。

我的 build.gradle 和类路径中有依赖项。

compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '2.1.2'

我有以下布局文件

    <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
    <meta charset="UTF-8" />
    <title>Default Template</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="author" content="" />
    <meta name="description" content="" />
    <meta name="title" content="" />
    <link rel="stylesheet" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body>

    <!-- header -->
    <header th:include="shared/nav-menu :: menu-admin" />

    <!-- page content -->
    <th:block>
        <section layout:fragment="content"></section>
    </th:block>

</body>
</html>

和文件内容:

    <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="default">
<head>
    <title>Parameter Manager</title>
</head>
<body>
    <section layout:fragment="content">
        <h2>OMG I am on the page!</h2>
    </section>
</body>
</html>

HTML 输出是 content.html 文件。它没有按预期工作。标题和导航菜单应该是 HTML 输出的一部分。页面源中也不应该是这种情况。

【问题讨论】:

  • 如果你查看:source,你还看到layout:fragment和layout:decorator属性吗,还是没有了?您是否尝试过其他 thymeleaf 标签来查看您的模板是否正在被评估?
  • 是的,在我的 login.html 中,不使用布局方言 thymeleaf 可以正常工作。我前段时间使用过相同的设置,但当时是 Spring Boot 1.2 或 1.3,所以可能发生了一些变化。

标签: spring spring-mvc spring-boot thymeleaf


【解决方案1】:

显然,最新版本的 Thymeleaf 布局方言不适用于 Spring Boot 1.5。使用 1.2.9 版,它按预期工作。

compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '1.2.9'

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-23
  • 2019-09-12
  • 2020-11-05
  • 2016-03-18
  • 2019-04-29
  • 2014-07-04
  • 2015-04-26
相关资源
最近更新 更多