thymeleaf - 百里香叶显示不正确
问题描述
有人能告诉我这些代码有什么问题吗。它只显示第一行和表头信息。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,否则会显示
你会想做这样的事情然后:
th:if="${!products.id.isEmpty()}"
这表示 - 如果您的产品列表的 id 不为空,则显示整个 div。
但是如果你想检查整个事情是否为 NULL,你可以这样做:
th:if="${products != null}"
这就是说 - 如果您的数组没有数据而不是显示。
推荐阅读
- swift - 如何为数组中的项目创建单独的表格视图?
- git - 是否可以在不分叉的情况下发送拉取请求
- c++ - 如何使用结构和指针推送和弹出一堆双打
- reactjs - 从 React 表中删除一个按钮
- python - 使用多线程模块将 API 数据检索到数据帧中
- pandas - 熊猫专栏没有永久改变
- amazon-web-services - DKIM 设置不会验证。社会经济地位
- java - java.lang.IndexOutOfBoundsException:索引:6,大小:0
- node.js - npx create-react-app 命令返回错误
- amazon-web-services - 为什么在调用转换和接收器操作时需要设置 `transformation_ctx` 参数才能使 AWS Glue 书签工作?