无法使百里香布局方言示例工作

问题描述 投票:1回答:1

我有一个春季启动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中的html

<p layout:decorate="{Layout}">
    My Custom Footer
</p>

我希望它返回Layout.html,并将页脚修改为content2.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-for-a-Spring-Boot-web-application

看起来有一些语法变化所以我使用的文档把我带到了错误的道路上。

java spring-boot thymeleaf
1个回答
0
投票

替换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>

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

© www.soinside.com 2019 - 2024. All rights reserved.