我有这个代码,其中tdk是我在springboot文件 application.properties
中定义的一个常见变量,名为 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)
如果您使用的是胸腺3,则可以使用片段表达式完成此操作。我认为它应该看起来像这样:
<head th:replace="~{${@environment.getProperty('myPropertyName') + '/common/header'} :: common-header}" />