【发布时间】:2021-04-15 05:42:48
【问题描述】:
我有一个带有 Thymeleaf UI 的 Spring Boot Web 项目。我的列表用户页面将所有地址字段组合如下:
<td>
<div class="container">
<span th:text="${tempUser.addressLine1}"></span>,<br>
<th:block th:if="${tempUser.addressLine2 eq null}">
</th:block>
<th:block th:if="${tempUser.addressLine2 ne null}">
<span th:text="${tempUser.addressLine2}"></span>,<br>
</th:block>
<span th:text="${tempUser.town}"></span>,<br>
County <span th:text="${tempUser.county}"></span>,<br>
<span th:text="${tempUser.country}"></span>,<br>
<span th:text="${tempUser.postcode}"></span>
</div>
</td>
问题在于,如果用户没有指定地址,它们会显示为:
如果用户没有输入任何内容,如何更改此地址以使地址显示为完全空白?
【问题讨论】:
-
只需为
div class="container"设置th:if 条件并包括null literal 检查与and连接
标签: java spring-boot thymeleaf