【问题标题】:Thymeleaf format for list within a HashMapHashMap 中列表的 Thymeleaf 格式
【发布时间】:2017-08-13 10:35:25
【问题描述】:

我正在尝试将具有值列表的模板放入哈希图中的键中,但是当我尝试将其放入模板中时,如果它自己落入新行中。

图片: 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>

【问题讨论】:

  • 您能否提供一张图片来描述您要归档的内容?

标签: java html spring thymeleaf


【解决方案1】:

您正在您的&lt;tr /&gt;s 中创建&lt;tr /&gt;s。查看 thymeleaf 生成的源代码应该会告诉您这一点。我猜你的 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>

【讨论】:

    猜你喜欢
    • 2020-02-22
    • 2012-10-19
    • 2018-07-08
    • 2013-12-20
    • 1970-01-01
    • 1970-01-01
    • 2017-02-13
    • 2017-03-29
    • 2019-09-27
    相关资源
    最近更新 更多