布局:装饰在百里香中不起作用

2024-02-18

我试图引入一种布局(如here https://ultraq.github.io/thymeleaf-layout-dialect/Examples.html)在我的应用程序中使用 thymeleaf 但无法让它工作。我已经查过了this https://stackoverflow.com/questions/28385056/thymeleaf-decorator-is-not-working post.

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.htmlhere https://ultraq.github.io/thymeleaf-layout-dialect/Examples.html#layouts。没有变化。添加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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

布局:装饰在百里香中不起作用 的相关文章

随机推荐