【问题标题】:Thymeleaf calling method on objectThymeleaf 在对象上调用方法
【发布时间】:2014-06-26 05:30:10
【问题描述】:

是否可以在 Thymeleaf 的“每个”循环中调用对象的方法?我正在尝试创建一个动态表,其中行和列都可以是动态的。一个表有一个行列表和一个列列表。 Column 有一个 getValue 方法,对于给定的 Row 可以获取该值。但我无法从 Thymeleaf 调用这个 getValue(Row row)。

我有这个 Thymeleaf 代码:

<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 中执行此操作,例如将变量传递给其他变量的方法?

【问题讨论】:

    标签: html-table thymeleaf


    【解决方案1】:

    我发现了问题,因为我向这个方法传递了一些东西,它不是一个 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>
    

    【讨论】:

      猜你喜欢
      • 2015-03-20
      • 1970-01-01
      • 2017-06-29
      • 1970-01-01
      • 1970-01-01
      • 2011-09-12
      • 1970-01-01
      • 1970-01-01
      • 2023-01-16
      相关资源
      最近更新 更多