【问题标题】:Only display address formatting information if the user has entered an address如果用户输入了地址,则仅显示地址格式信息
【发布时间】: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


【解决方案1】:

我使用@Slava Ivanov 的建议将null literal 检查与and 连接在一起。我希望这张支票的粒度更细一些,所以把它放在每个th 中。这是我的代码:

<td>
    <div class="container">
        <th:block th:if="${tempUser.addressLine1 eq null and tempUser.addressLine1 eq ''}">
        </th:block>
        <th:block th:if="${tempUser.addressLine1 ne null and tempUser.addressLine1 ne ''}">
            <span th:text="${tempUser.addressLine1}"></span>,<br>
        </th:block>
        <th:block th:if="${tempUser.addressLine2 eq null and tempUser.addressLine2 eq ''}">
        </th:block>
        <th:block th:if="${tempUser.addressLine2 ne null and tempUser.addressLine2 ne ''}">
            <span th:text="${tempUser.addressLine2}"></span>,<br>
        </th:block>
        <th:block th:if="${tempUser.town eq null and tempUser.town eq ''}">
        </th:block>
        <th:block th:if="${tempUser.town ne null and tempUser.town ne ''}">
            <span th:text="${tempUser.town}"></span>,<br>
        </th:block>
        <th:block th:if="${tempUser.county eq null and tempUser.county eq ''}">
        </th:block>
        <th:block th:if="${tempUser.county ne null and tempUser.county ne ''}">
            County <span th:text="${tempUser.county}"></span>,<br>
        </th:block>
        <th:block th:if="${tempUser.country eq null and tempUser.country eq ''}">
        </th:block>
        <th:block th:if="${tempUser.country ne null and tempUser.country ne ''}">
            <span th:text="${tempUser.country}"></span>,<br>
        </th:block>
        <th:block th:if="${tempUser.postcode eq null and tempUser.postcode eq ''}">
        </th:block>
        <th:block th:if="${tempUser.postcode ne null and tempUser.postcode ne ''}">
            <span th:text="${tempUser.postcode}"></span>
        </th:block>
    </div>
</td>

【讨论】:

    【解决方案2】:

    我想您正在寻找的技术是允许 max_dist 成为距离向量guide,其中您可以执行 stringdist_inner_join(..., max_dist=c(zero,2))。不幸的是,虽然有人要求这样做

    【讨论】:

      猜你喜欢
      • 2016-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多