首页 > 解决方案 > 百里香叶显示不正确

问题描述

有人能告诉我这些代码有什么问题吗。它只显示第一行和表头信息。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>

标签: thymeleaf

解决方案


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

你会想做这样的事情然后:

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

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

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

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

这就是说 - 如果您的数组没有数据而不是显示。


推荐阅读