无法获得胸腺布局方言示例



我有一个Springboot 1.5.9项目,我试图使百里多夫布局方言模板正常工作。

我遵循此处给出的示例

https://ultraq.github.io/thymeleaf-layout-dialect/examples.html

我已经创建了一个Layout.html,并具有以下代码

<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
    <title>Layout page</title>
    <script src="common-script.js"></script>
</head>
<body>
<header>
    <h1>My website</h1>
</header>
<section layout:fragment="content">
    <p>Page content goes here</p>
</section>
<footer>
    <p>My footer</p>
    <p layout:fragment="custom-footer">Custom footer here</p>
</footer>
</body>
</html>

和一个带有以下

的content2.html
<p layout:decorate="{Layout}" layout:fragment="custom-footer">
    My Custom Footer
</p>

我的控制器看起来像

@RequestMapping(path = "/")
public String intialiseService(Model model) {
    return "content2";
}

当我访问root时,我只需从content2.html

就可以返回一个页面。
<p layout:decorate="{Layout}">
    My Custom Footer
</p>

我希望它可以将其修改为content2.html内容返回layout.html

任何建议都非常感激。

更新 我忘了添加我的依赖项:

dependencies {
    compile('org.springframework.boot:spring-boot-starter-actuator')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile "io.springfox:springfox-swagger2:2.6.1" //rest api description
    compile 'io.springfox:springfox-swagger-ui:2.6.1' //rest api description ui
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('info.cukes:cucumber-java:1.2.5') //to use cucumber
    testCompile('info.cukes:cucumber-junit:1.2.5') //to run in junit via the ide
    testCompile('info.cukes:cucumber-spring:1.2.5') //to use dependency injection
    acceptanceTestCompile('org.springframework:spring-tx:4.3.6.RELEASE') //to run acceptance tests from feature file in IDE
    compile "org.scala-lang:scala-library:${SCALA_VERSION}"
    loadTestCompile "io.gatling:gatling-http:${GATLING_VERSION}"
    loadTestCompile "io.gatling:gatling-core:${GATLING_VERSION}"
    loadTestCompile "io.gatling.highcharts:gatling-charts-highcharts:${GATLING_VERSION}"
    testCompile "io.gatling:gatling-app:${GATLING_VERSION}"
    compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: '2.9.2'
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
    compile("org.springframework.boot:spring-boot-devtools")
    compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '1.1.3'
}

第二个更新:

这使它起作用

https://progressive-code.com/post/14/thymeleaf-layout-dialect-as-decorator-pattern-pattern-for-a-spring-boot-boot-web-papplication

看起来有一些语法更改,所以我使用的文档将我带到了错误的路径上。

content2.html中的代码替换: <p layout:decorate="{Layout}" layout:fragment="custom-footer"> My Custom Footer </p>

与此:

<p layout:decorate="~{Layout}" layout:fragment="custom-footer"> My Custom Footer </p>

我猜你缺少的~在定义的装饰器前面。

最新更新