Thymeleaf中组合th:field的内循环

时间:2019-10-02 12:00:41

标签: java spring-boot thymeleaf

我正在使用Java / Spring / Thymeleaf制作Web应用程序,但在使用th:field查看列表中的HashMaps数据时遇到问题。我上课:

public class CompleteMeasurementResult {    
    private List<MeasurementResult> measurementResults;

// getter, setter, constructor
}

`public class MeasurementResult{
    private Map<Long, SurfaceResult> groupedSurfaceResultByTaskType;

// getter, setter, constructor
}`

public class SurfaceResult  {
    private Double timeDuration;

    // getter, setter, constructor
}

和模板,其中completeMeasurementResult位于th:object

<form action="#" th:action="@{/reCountMeasurement}" th:object="${completeMeasurementResult}" method="post">
<table class="measurementResults">
    <tbody>
    <tr th:each="measurementResult, measurementResultStat : *{measurementResults}"

        <div th:each="surface, surfaceStat : *{measurementResults[__${measurementResultStat.index}__].groupedSurfaceResultByTaskType}">
            <td><input type="text" th:field="*{measurementResults[__${measurementResultStat.index}__].groupedSurfaceResultByTaskType[__${surfaceStat.index}__].timeDuration}" readonly="readonly" /></td>
        </div>
    </tr>
    </tbody>
</table>

<input type="submit" value="Submit" />

出现异常

org.thymeleaf.TemplateEngine - [THYMELEAF][http-nio-8080-exec-1] Exception processing template "mixedChart": null
java.util.ConcurrentModificationException: null
    at java.util.HashMap$HashIterator.nextNode(HashMap.java:1442)
    at java.util.HashMap$EntryIterator.next(HashMap.java:1476)
    at java.util.HashMap$EntryIterator.next(HashMap.java:1474)
    at org.thymeleaf.engine.IteratedGatheringModelProcessable.process(IteratedGatheringModelProcessable.java:276)
    at org.thymeleaf.engine.ProcessorTemplateHandler.handleCloseElement(ProcessorTemplateHandler.java:1640)
    at org.thymeleaf.engine.CloseElementTag.beHandled(CloseElementTag.java:139)
    at org.thymeleaf.engine.Model.process(Model.java:282)
    at org.thymeleaf.engine.Model.process(Model.java:290)

我是Thymeleaf的新手,非常感谢任何解决方案。 谢谢你,彼得。

1 个答案:

答案 0 :(得分:0)

我通过更改代替的MeasurementResult结构来解决此问题 私人地图groupedSurfaceResultByTaskType; 通过 私有列表groupedSurfaceResultByTaskType;

在Thymeleaf模板中比 * {measurementResults [ $ {measurementResultStat.index} ]。groupedSurfaceResultByTaskType [ $ {surfaceStat.index} ]。timeDuration} 会工作。