2014-05-08 92 views
3

是否可以在Thymeleaf的「each」循環中的對象上調用方法?我試圖創建一個動態表,其中行和列都可以是動態的。表格包含行列表和列列表。列有一個方法getValue,對於給定的Row可以獲取該值。但是我無法從Thymeleaf調用這個getValue(Row row)。對象上的Thymeleaf調用方法

我有這樣的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,例如將變量傳遞給其他變量的方法?

回答

11

我發現這個問題,因爲我傳遞東西,這種方法它不是一個getter方法,所以我必須提供完整的方法名的getValue不僅僅是值:

<table> 
     <tr th:each="row : ${table.rows}"> 
      <td th:each="column : ${table.columns}"> 
       <span th:text="${column.getValue(row)}"/> 
      </td> 
     </tr> 
    </table>