Thymeleaf Table issues with rowspan (1 Order, N Articles)(包含行跨度的百里叶表问题(1个订单,N篇文章))
问题描述
我正在为订购系统创建一个简单的Intranet Web视图,以显示当前正在处理的所有订单。然而,我坚持使用胸腺叶标记:
public class Order {
private Factory factory;
private String orderNumber;
private Date orderDate;
....
private List<Article> articles;
}
public class Article {
private String number;
private String name;
}
我想要实现的内容如下(1个订单+3篇文章按此顺序):
<table class="table table-striped table-hover table-middle table-condensed table-bordered">
<thead>
<tr>
<th>OrderNr</th>
<th>Date</th>
<th>Article Number</th>
<th>ArticleName</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="3">Order 32</td>
<td rowspan="3">27.03.2020</td>
<td>17442</td>
<td>Screws</td>
</tr>
<tr>
<td>023423</td>
<td>Potatoe</td>
</tr>
<tr>
<td>32342</td>
<td>YetAnotherItem</td>
</tr>
</tbody>
</table>
所有常见的内容应该在所有文章中排成一行,并且应该每行查看一篇文章。然而,我不知道如何用两个TH来实现这一点:每个TH(一个用于订单,一个用于订单的物品)。我可以在标记中使用大量的if来"展平"我的视图(每行由一个Line-Object表示),但在我看来,这是一个非常肮脏的变通……
有人能帮我找到更好的解决方案吗?
非常感谢!
推荐答案
<table>
<thead>
<tr>
<th>OrderNr</th>
<th>Date</th>
<th>Article Number</th>
<th>ArticleName</th>
</tr>
</thead>
<tbody>
<div th:remove="tag" th:each="order:${orderList}"
th:with="articleCount=${order.articleList.size()}">
<tr>
<td th:text="${order.orderNumber}" th:rowspan="${order.articleList.size()}"></td>
<td th:text="${order.orderDate}" th:rowspan="${order.articleList.size()}"></td>
<td th:text="${articleCount>0}?${order.articles[0].number}:''"></td>
<td th:text="${articleCount>0}?${order.articles[0].name}:''"></td>
</tr>
<tr th:each="article,stats:${order.articles}" th:if="${!stats.first}">
<td th:text="${article.number}"></td>
<td th:text="${article.name}"></td>
</tr>
</div>
</tbody>
</table>
th:remove="tag"
For Removediv
For Removediv
TABLE生成后。
已更改以避免呈现问题。感谢@Martin C.的comment
这篇关于包含行跨度的百里叶表问题(1个订单,N篇文章)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:包含行跨度的百里叶表问题(1个订单,N篇文章)


基础教程推荐
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01