包含行跨度的百里叶表问题(1个订单,N篇文章) [英] Thymeleaf Table issues with rowspan (1 Order, N Articles)

查看:70
本文介绍了包含行跨度的百里叶表问题(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 RemovedivFor RemovedivTABLE生成后。

已更改以避免呈现问题。感谢@Martin C.的comment

这篇关于包含行跨度的百里叶表问题(1个订单,N篇文章)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆