我有两个环境,并且图像有不同的链接。
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>
假设 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')}}"/>