【问题标题】:thymeleaf not displaying properly百里香叶显示不正确
【发布时间】:2018-11-19 12:47:13
【问题描述】:

有人能告诉我这些代码有什么问题吗。它只显示第一行和表头信息。thks

`<div class="container">
<div th:if="${not #lists.isEmpty(products)}">
    <h2>List of Products</h2>
    <table class="table table-striped" th:width="700px">
        <tr>
            <th>Id</th>
            <th>Description</th>
            <th>Price</th>
            <th>Image Url</th>
        </tr>
        <tr th:each="product : ${products}">
            <td th:text="${product.id}"></td>
            <td th:text="${product.description}"></td>
            <td th:text="${product.price}"></td>
            <td th:text="${product.imageUrl}"></td>
        </tr>
    </table>
</div>

【问题讨论】:

  • 您有两个开始 div 和一个结束 div。这是您在此处所做的复制粘贴中的错误吗?请您复制并粘贴整个页面的 html 代码吗?另外,你有多少产品?能把你的控制器的代码贴出来吗?

标签: thymeleaf


【解决方案1】:

您似乎想说:如果该区域不是空的而不是显示...如果是这样,您的百里香叶设置不正确。对于一个超级简单的修复,我只需检查数组中的一个元素,如果没有数据则隐藏整个 div,否则会显示

那么你会想做这样的事情:

th:if="${!products.id.isEmpty()}"

这表示 - 如果您的产品列表的 id 不为空,则显示整个 div。

但是如果你想检查整个事情是否为 NULL,你可以这样做:

th:if="${products != null}"

也就是说 - 如果您的数组没有数据,则不显示。

【讨论】:

    猜你喜欢
    • 2020-02-19
    • 1970-01-01
    • 2018-10-12
    • 2016-08-14
    • 2015-11-29
    • 1970-01-01
    • 2015-12-09
    • 2018-07-08
    相关资源
    最近更新 更多