gpt4 book ai didi

spring - 布局 :decorate is not working in thymeleaf

转载 作者:行者123 更新时间:2023-12-04 01:59:29 26 4
gpt4 key购买 nike

我正在尝试使用 thymeleaf 在我的应用程序中引入布局(如 here ),但无法使其正常工作。我已经查过了this邮政。

pom.xml

    <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
...
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>

这是我的 MvcConfig
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
...
@Bean
public LayoutDialect layoutDialect() {
return new LayoutDialect();
}
}

layout.html 给定 here .没有变化。已添加 xmlns:th="http://www.thymeleaf.org在检查一些文章。
<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Layout page</title>
</head>
<body>
<header>
<h1>My website</h1>
</header>
<div layout:fragment="content">
<p>Page content goes here</p>
</div>
<footer>
<p>My footer</p>
<p layout:fragment="custom-footer">Custom footer here</p>
</footer>
</body>
</html>

我正在尝试替换 login.html 中如下所示的内容片段
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
layout:decorate="~{layout}">
<head>
<title>Application Login</title>
</head>
<body>
<div layout:fragment="content">
<div th:if="${param.error}">
Invalid username and password.
</div>
<div th:if="${param.logout}">
You have been logged out.
</div>
<form th:action="@{/login}" method="post">
<div><label> User Name : <input type="text" name="username" value=""/> </label></div>
<div><label> Password: <input type="password" name="password" value=""/> </label></div>
<div><input type="submit" value="Sign In"/></div>
</form>
</div>
</body>
</html>

我错过了什么吗?

最佳答案

以下对我有用。

    <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
...
<!--<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>-->

<properties>
...
<thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
</properties>

关于spring - 布局 :decorate is not working in thymeleaf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48355548/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com