8
我有这样的一段代码,其中TDK是我在名为SpringBoot文件application.properties
定义的公共变量server.contextPath
Thymeleaf读取属性内更换
我想知道是否有一种方法来替代它
<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)
“〜{$ {@ environment.getProperty('server.contextPath')+'/ common/header'}”,模板可能不存在或可能不可访问通过任何配置的模板解析器(/ tdk/login/login:6) \t at –
那么,你是否证实生成的字符串与你真正想要的匹配?我无法验证值@ environment.getProperty('server.contextPath')。 – Metroids
它似乎不会替换变量 –