2017-05-05 16 views
8

Tôi có đoạn mã này, nơi tdk là một biến chung tôi đã xác định trong tập tin SpringBoot application.properties tên server.contextPathThymeleaf đọc tài sản bên trong một thay thế

Tôi muốn biết nếu có một cách để thay thế nó cho

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

cái gì đó như

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

tôi đang sử dụng

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

Tôi cũng đã thử:

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

với kết quả này:

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) 

Trả lời

2

Nếu bạn đang sử dụng thymeleaf 3, bạn có thể thực hiện điều này bằng fragment expressions. Tôi nghĩ rằng nó sẽ giống như thế này:

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

"~ {$ {@ environment.getProperty ('server.contextPath') + '/ common/header'}", mẫu có thể không tồn tại hoặc có thể không truy cập được bởi bất kỳ Trình giải quyết mẫu đã định cấu hình nào (/ tdk/login/login: 6) \t tại –

+0

Vâng, bạn đã xác minh rằng chuỗi được tạo phù hợp với những gì bạn thực sự muốn? Tôi không thể xác minh giá trị @ environment.getProperty ('server.contextPath'). – Metroids

+0

có vẻ như nó không thay thế biến –

Các vấn đề liên quan