图片
默认无图 01
by 张侃
html
<div class="media" th:each="item:${partyTitle}">
<div class="pull-left">
<th:block th:if="${!#strings.isEmpty(item.listImage)}">
<img th:src="${item.listImage}" width="120" height="90" alt="">
</th:block>
<th:block th:unless="${!#strings.isEmpty(item.listImage)}">
<img src="/res/img/default-img.png" width="120" height="90" alt="默认图片">
</th:block>
</div>
<a
class="listlineClamp"
th:href="${item.article.pcUrl}"
th:text="${item.listTitle}"
>
</a>
</div>简化版本
html
<!-- isEmpty 显示默认图 -->
<th:block th:if="${#strings.isEmpty(item.listImage)}">
<img src="/assets/images/home/cover/1.png" draggable="false">
</th:block>
<th:block th:unless="${#strings.isEmpty(item.listImage)}">
<img th:src="${item.listImage}" draggable="false">
</th:block>默认无图 02
by chat gpt
html
<img
th:src="${#strings.isEmpty(item.listImage) ? '/images/default.png' : item.listImage}"
alt="图片"
/>