HashMap中列表的Thymeleaf格式

时间:2017-03-21 16:12:46

标签: java html spring thymeleaf

我试图将具有值列表的模板放在散列映射中的键中,但是当我尝试将其放入模板中时,如果单独转入新行。

照片: Problem Thymeleaf代码的一部分:

    <div class="container">
    <h1 class="text-center">Boards</h1>
    <hr />
    <table class="table table-striped">
        <tr>
            <th>Board Name</th>
            <th>Investor</th>
            <th>Fuse Manufacturer</th>
            <th>Fuse Nr. Of Poles</th>
            <th>Fuse Characteritics</th>
            <th>Fuse Amount</th>
        </tr>
        <th:block th:each="item, iterStat : ${map}" varStatus="status">
            <tr>
                <td th:text="${item.key.name}"></td>
                <td th:text="${item.key.investor}"></td>
                <tr th:each="fuse : ${item.value}">
                    <td th:text="${fuse.fuse.manufacturer.name}"></td>
                    <td th:text="${fuse.fuse.type}"></td>
                    <td th:text="${fuse.fuse.characteristics}"></td>
                    <td th:text="${fuse.quantity}"></td>
                </tr>
            </tr>
        </th:block>
    </table>
</div>

1 个答案:

答案 0 :(得分:0)

您正在<tr />中创建<tr />。看看百里香叶产生的来源应该告诉你这个。我猜你的HTML应该是这样的:

<table class="table table-striped">
  <tr>
    <th>Board Name</th>
    <th>Investor</th>
    <th>Fuse Manufacturer</th>
    <th>Fuse Nr. Of Poles</th>
    <th>Fuse Characteritics</th>
    <th>Fuse Amount</th>
  </tr>

  <th:block th:each="item: ${map}">
    <tr th:each="fuse: ${item.value}">
      <td th:text="${item.key.name}" />
      <td th:text="${item.key.investor}" />
      <td th:text="${fuse.fuse.manufacturer.name}" />
      <td th:text="${fuse.fuse.type}" />
      <td th:text="${fuse.fuse.characteristics}" />
      <td th:text="${fuse.quantity}" />
    </tr>
  </th:block>
</table>