Nuñ*_*ada 8 thymeleaf spring-boot
我有这样的代码段,其中,TDK是我在SpringBoot文件中定义的通用变量application.properties
命名server.contextPath
我想知道是否有办法替换它
<head th:replace="tdk/common/header :: common-header" />
Run Code Online (Sandbox Code Playgroud)
就像是
<head th:replace="@environment.get('server.contextPath')/common/header :: common-header" />
Run Code Online (Sandbox Code Playgroud)
我在用
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.5.3.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
<head th:replace="~{${@environment.getProperty('serverContextPath') + '/common/header'} :: common-header}" />
Run Code Online (Sandbox Code Playgroud)
结果如下:
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)
Run Code Online (Sandbox Code Playgroud)
如果您使用的是 thymeleaf 3,则可以使用片段表达式来完成此操作。我认为它应该看起来像这样:
<head th:replace="~{${@environment.getProperty('myPropertyName') + '/common/header'} :: common-header}" />
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
488 次 |
最近记录: |