遍历百里香的集合

时间:2019-01-09 13:14:54

标签: spring-mvc thymeleaf

我需要循环进入路线中的点集合 我有这样的东西:

<tr th:if="${routes!=null}" th:each="route : ${routes}">
            <td><span th:text="${route?.name}"> name </span></td>
            <td><span th:text="${route?.pointsForRoute}"> pointsForRoute </span></td>
            <td><span th:text="${route?.routeLength}"> routeLength </span></td>
            <td><span th:text="${route?.heightDiffrence}"> heightDiffrence </span></td>
            <tr th:if="${route.points!=null}" th:each="point : {route?.points}">
            <td><span th:text="${point?.name}"> name </span></td>
        </tr>

我得到的原因是:org.thymeleaf.exceptions.TemplateProcessingException:无法解析为每个:“ point:{route?.points}”(模板:“ show-routes”-第41行,第51栏)< / p>

路线类别:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
int id;

@Column(name="name")
String name;

@Column(name="points")
int pointsForRoute;

@Column(name="length")
double routeLength;

@Column(name="heightDiffrence")
int heightDiffrence;

@ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.REFRESH, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH})
@JoinTable(name = "PunktyTrasy",
joinColumns = @JoinColumn(name="idT"),
inverseJoinColumns = @JoinColumn(name = "idP"))
private List<Point> points = new ArrayList<>();

谢谢您的帮助!

1 个答案:

答案 0 :(得分:1)

您在th:each =“ point:{route?.points}”中忘记了$ 所以替换

th:each="point : {route?.points}"

使用

th:each="point : ${route?.points}"