gpt4 book ai didi

spring-boot - Thymeleaf 读取替换内的属性

转载 作者:行者123 更新时间:2023-12-04 08:47:39 32 4
gpt4 key购买 nike

我有这段代码,其中tdk是我在SpringBoot文件application.properties中定义的公共(public)变量命名为 server.contextPath
我想知道是否有办法替换它

<head th:replace="tdk/common/header :: common-header" />

就像是
<head th:replace="@environment.get('server.contextPath')/common/header :: common-header" />

我在用
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>

我也试过:
<head th:replace="~{${@environment.getProperty('serverContextPath') + '/common/header'} :: common-header}" />

结果:
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "~{${@environment.getProperty('serverContextPath') + '/common/header'}", template might not exist or might not be accessible by any of the configured Template Resolvers (/tdk/registration/signup:6)

最佳答案

如果你使用的是 thymeleaf 3,你可以使用 fragment expressions 来完成。 .我认为它应该看起来像这样:

<head th:replace="~{${@environment.getProperty('myPropertyName') + '/common/header'} :: common-header}" />

关于spring-boot - Thymeleaf 读取替换内的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43810963/

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