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
它似乎不會替換變量 –