相关疑难解决方法(0)

迁移到 Thymeleaf 3 后,Thymeleaf 停止解析布局模板

我有一个简单的 Spring Boot 应用程序,版本为 1.5.7,我正在尝试将其迁移到版本 2.0.0。我快完成了,但还缺少最后一块,那就是百里香叶。

旧版本中一切正常,但迁移后,Spring Boot 停止解析任何模板(页面和电子邮件)。

我有所有模板src/main/resources/templates。另外,我有一个名为默认的布局,src/main/resources/templates/layout如下所示:

<!DOCTYPE html>
<html>
<head th:replace="fragments/header :: head"></head>
<body>

    <div id="page">
        <nav class="navigation" th:replace="fragments/navigation"></nav>

        <div class="container">
            <div layout:fragment="container"></div>
        </div>
    </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我的页面链接到此布局,如下所示:

<!DOCTYPE html>
<html lang="en"
  xmlns:th="http://www.thymeleaf.org"
  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
  layout:decorate="layout/default">

<body>

    <div layout:fragment="container">
...
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

导航片段位于src/main/resources/templeats/fragments

在 Spring Boot 2 中,渲染了登录页面,但未应用布局(因此缺少导航栏和样式)。2.0.0版本有什么变化吗?我在官方文档或迁移指南中没有找到任何解决方案。

编辑:正如答案中所建议的,这是由迁移到 Thymeleaf 3 引起的。我用一些反映迁移指南的更改更新了我的问题,但代码仍然没有注入布局。

layout:data-layout-decorate=~{layout/default}也尝试过布局:data-layout-decorate=~{layout/default.html}

我通过手动添加 thymeleaf 方言依赖项来使其工作:

compile('nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect')
Run Code Online (Sandbox Code Playgroud)

但我认为这应该是 Spring 中已经存在的传递依赖项,我不应该手动添加它......

java thymeleaf spring-boot

5
推荐指数
2
解决办法
4372
查看次数

标签 统计

java ×1

spring-boot ×1

thymeleaf ×1