【发布时间】:2018-04-29 06:10:35
【问题描述】:
我正在使用以下图像代码,该代码仅在图像存在时才显示。
<img th:if="${!ad.adPhotos.empty}" th:src="|/imageDisplay?id=${ad.adPhotos[0].id}|" alt="" class="img-respocive" />
我想为 else caluse 显示这个
<img height="150" width="150" src="img/NoPicAvailable.png" />
Thymeleaf 如何做到这一点?
【问题讨论】:
-
为什么不只是
<img th:if="${ad.adPhotos.empty}" height="150" width="150" th:src="img/NoPicAvailable.png" />?甚至使用th:switch? -
@bphilipnyc 我结束了使用
th:if="${ad.adPhotos.empty}" -
另一种方法
th:src= "${ad.adPhotos.empty ? 'img/NoPicAvailable.png' : '/imageDisplay?id=' + ad.adPhotos[0].id}" -
@MohamedSanaulla 我也喜欢你的方法
标签: thymeleaf