如何在 Spring Boot thymlef 中使用 application.yaml 文件中的 html 网页的图像链接

问题描述 投票:0回答:1

我有两个环境,并且图像有不同的链接。

application.yaml

image
   url: prod-env-link

application-dev.yaml

image 
   url: prod-env-link

如何在 Spring Boot thymeleaf 中使用 html 网页中的图像链接来根据环境选择图像。

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Some title</title>
</head>
<body>
    <img th:src="image-link" />
</body>
</html>
spring-boot thymeleaf
1个回答
0
投票

假设 image.url 是一个 URL,而不是 src/main/resources/static 项目文件夹中图像的路径,您将获得如下图像:

<img th:src="${@environment.getProperty('image.url')}"/>

如果 image.url 是 src/main/resources/static 中图像的路径,您将使用:

<img th:src="@{${@environment.getProperty('image.url')}}"/>
© www.soinside.com 2019 - 2024. All rights reserved.