Thymeleaf,地图对象,具有作为地区列表的值。?

时间:2019-04-15 18:47:50

标签: list spring-boot dictionary thymeleaf

假设我们有一个Map对象,其中以State为键,而State的地区列表为Value。这就是我在此类Map对象上进行迭代的方式,但是每个区域都不会在新行上打印。有人可以帮忙吗???

<div th:if="${not #lists.isEmpty(stateToDistrictMap)}">
   <table>
     <tr><td>State</td><td>Districts</td></tr>
 <th:block th:each="state : ${stateToDistrictMap}">
   <tr>
     <td th:text="${state.key}">State</td>
  <th:block th:each="district : ${state.value}">
    <td th:text="${district.name}">District</td>
    <td th:text="${district.code}">District</td>
    <td th:text="${district.erstyear}">District</td>
    <td th:text="${district.info}">District</td>
  </th:block>
   </tr>
 </th:block>
     </table>
</div>

有人可以帮忙吗???

1 个答案:

答案 0 :(得分:1)

您可能想要类似的东西:

<div th:if="${not #lists.isEmpty(stateToDistrictMap)}">
    <table>
        <tr>
            <td>State</td>
            <td>Districts</td>
        </tr>

        <th:block th:each="state: ${stateToDistrictMap}">
          <tr th:each="district, i: ${state.value}">
            <td th:text="${i.first ? state.key : ' '}" />
            <td th:text="${district.name}" />
            <td th:text="${district.code}" />
            <td th:text="${district.erstyear}" />
            <td th:text="${district.info}" />
          </tr>
        </th:block>
    </table>
</div>