Java 如何在Spring Boot中从Thymeleaf模板调用方法?

Java 如何在Spring Boot中从Thymeleaf模板调用方法?,java,spring-boot,thymeleaf,Java,Spring Boot,Thymeleaf,我在CommonUtils类中创建了一个方法,我试图在Thymeleaf中调用它,但它抛出了错误 EL1004E:方法调用:方法ConvertSectoHmm(java.lang.Integer) 在类型com.exm.util.CommonUtils上找不到 这是我在特里梅莱夫写的 <td th:text="${T(com.exm.util.CommonUtils).ConvertSecToHHMM(recentActivities.timeSpent)}">&

我在CommonUtils类中创建了一个方法,我试图在Thymeleaf中调用它,但它抛出了错误

EL1004E:方法调用:方法ConvertSectoHmm(java.lang.Integer) 在类型com.exm.util.CommonUtils上找不到

这是我在特里梅莱夫写的

<td th:text="${T(com.exm.util.CommonUtils).ConvertSecToHHMM(recentActivities.timeSpent)}"></td>
我得到这个错误

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method ConvertSecToHHMM in com.exm.configurations.MyConfigurations required a bean of type 'int' that could not be found.

是否有任何方法可以在单独的类中创建util方法,并且可以随时从Thymeleaf调用它们?

您的应用程序启动失败
@Bean
方法,spring无法找到值
n
来创建Bean。因此,您需要删除Bean方法并使用以下语法调用CommonUtils方法:

<p th:text="${@commonUtils.ConvertSecToHHMM(500)}"></p>

首先,如果您的方法是纯函数,为什么不希望它是静态的?
***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method ConvertSecToHHMM in com.exm.configurations.MyConfigurations required a bean of type 'int' that could not be found.
<p th:text="${@commonUtils.ConvertSecToHHMM(500)}"></p>