Thymeleaf Table issues with rowspan (1 Order, N Articles)(包含行跨度的百里叶表问题(1个订单,N篇文章))
本文介绍了包含行跨度的百里叶表问题(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篇文章)


基础教程推荐
猜你喜欢
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13