Spring Boot Thymeleaf 布局方言不起作用 [英] Spring Boot Thymeleaf Layout Dialect Not Working

查看:74
本文介绍了Spring Boot Thymeleaf 布局方言不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I just created a new Spring Boot v1.5 project and facing issue where Thymeleaf Layout Dialect is not working.

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

I have the dependencies in my build.gradle and its on the classpath.

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 输出的一部分.此外,页面源代码中不应该是这种情况.

The HTML output is content.html file. It is not working as intended. The header and navigation menu should be part of the HTML output. Also the is in the page source which should not be the case.

推荐答案

显然最新版本的 Thymeleaf Layout Dialect 不适用于 Spring Boot 1.5.使用版本 1.2.9,它按预期工作.

Apparently the latest version of Thymeleaf Layout Dialect doesn't work with Spring Boot 1.5. Using version 1.2.9 and it works as expected.

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

这篇关于Spring Boot Thymeleaf 布局方言不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆