2017-11-15 1 views
0

画像が存在する場合のみ画像を表示する次の画像コードを使用しています。Thymeleafは存在しなければ別の画像を表示します

<img th:if="${!ad.adPhotos.empty}" th:src="|/imageDisplay?id=${ad.adPhotos[0].id}|" alt="" class="img-respocive" /> 

私は、これはThymeleafで行われるだろうか

<img height="150" width="150" src="img/NoPicAvailable.png" /> 

caluse他のためにこれを表示したいですか?

+1

」だけではないのはなぜですか?あるいは 'th:switch'を使ってもいいですか? – bphilipnyc

+0

https://stackoverflow.com/questions/13494078/how-to-do-if-el---thymeleaf – bphilipnyc

+0

@bphilipnyc「th:if = "$ {ad.adPhotos.empty}」「 – Arya

答えて

0

は、私は個人的に、このようにそれを行うだろう:追記として

<img th:unless="${ad.adPhotos.empty}" th:src="|/imageDisplay?id=${ad.adPhotos[0].id}|" alt="" class="img-respocive" /> 
<img th:if="${ad.adPhotos.empty}"height="150" width="150" src="img/NoPicAvailable.png" /> 

、私はthymeleaf URL構文ではなく、文字列の連結でSRCを生成するだろうと思います。

<img th:unless="${ad.adPhotos.empty}" th:src="@{/imageDisplay(id=${ad.adPhotos[0].id})}" alt="" class="img-respocive" /> 
関連する問題