Thymeleaf - 表格数据 table returns 零记录(空列表)时的建议方法?
Thymeleaf - Suggested approach when tabular data table returns zero records (empty list)?
鉴于:
<table id="identification-data" class="pure-table">
<thead>
<tr>
<th>Name</th>
<th>DOB</th>
<th>Gender</th>
<tr>
</thead>
<tbody>
<tr th:each="row : ${identificationData}">
<td th:text="${row['Name']}">Brian Smith</td>
<td th:text="${#calendars.format(row['Date of Birth'], 'MM/dd/yyyy')}">10/11/1971</td>
<td th:text="${row['Gender']}">Male</td>
</tr>
</tbody>
</table>
如果集合 ${identificationData} 为空 - 是否有 thymeleafy 方式来显示 "no data found" 之类的消息?
我可以在控制器端做一些事情,比如:
if (identificationData.isEmpty()){
model.addAttribute("identificationDataNotFound", Boolean.TRUE);
}
model.addAttribute("identificationData", identificationData);
我能想到的最 "thymeleafy" 方法是在列表为空时有条件地呈现包含 "No data found" 消息的 <tbody>
。您可以使用实用程序对象 #lists
检查 UI 中的列表是否为空(为您节省一个布尔模型属性)
<tbody th:if="${not #lists.isEmpty(identificationData)}">
<tr th:each="row : ${identificationData}">
...
</tr>
</tbody>
<tbody th:if="${#lists.isEmpty(identificationData)}">
<tr>
<td colspan="3">No Data found</td>
</tr>
</tbody>
鉴于:
<table id="identification-data" class="pure-table">
<thead>
<tr>
<th>Name</th>
<th>DOB</th>
<th>Gender</th>
<tr>
</thead>
<tbody>
<tr th:each="row : ${identificationData}">
<td th:text="${row['Name']}">Brian Smith</td>
<td th:text="${#calendars.format(row['Date of Birth'], 'MM/dd/yyyy')}">10/11/1971</td>
<td th:text="${row['Gender']}">Male</td>
</tr>
</tbody>
</table>
如果集合 ${identificationData} 为空 - 是否有 thymeleafy 方式来显示 "no data found" 之类的消息?
我可以在控制器端做一些事情,比如:
if (identificationData.isEmpty()){
model.addAttribute("identificationDataNotFound", Boolean.TRUE);
}
model.addAttribute("identificationData", identificationData);
我能想到的最 "thymeleafy" 方法是在列表为空时有条件地呈现包含 "No data found" 消息的 <tbody>
。您可以使用实用程序对象 #lists
检查 UI 中的列表是否为空(为您节省一个布尔模型属性)
<tbody th:if="${not #lists.isEmpty(identificationData)}">
<tr th:each="row : ${identificationData}">
...
</tr>
</tbody>
<tbody th:if="${#lists.isEmpty(identificationData)}">
<tr>
<td colspan="3">No Data found</td>
</tr>
</tbody>