是否可以在Thymelaf中的“each”循环中调用对象上的方法?我正在尝试创建一个动态表,其中行和列都可以是动态的。表具有行列表和列列表。列有一个方法getValue,对于给定的Row可以获取该值。但我无法从Thymelaaf调用这个getValue(Row行)。
我有这个百里香代码:
<table>
<tr th:each="row : ${table.rows}">
<td th:each="column : ${table.columns}">
<span th:text="${column.value(row)}"/>
</td>
</tr>
</table>
这会导致异常:
Exception evaluating SpringEL expression: "column.value(row)"
是否可以在 Thymeleaf 中执行此操作,例如将变量传递给其他变量的方法?
我发现了问题,因为我向这个方法传递了一些东西,它不是一个getter方法,所以我必须提供完整的方法名称:getValue
而不仅仅是value
:
<table>
<tr th:each="row : ${table.rows}">
<td th:each="column : ${table.columns}">
<span th:text="${column.getValue(row)}"/>
</td>
</tr>
</table>