简体   繁体   中英

How to refer to a static method in Thymeleaf html in java?

I need to use the getMoneyIntoWords() method in the invoice html. But I am getting errors. Refer the code and errors below

// Added below method in MoneyUtil.java

 public String getMoneyIntoWords(String input) {

        MoneyConverters converter = MoneyConverters.ENGLISH_BANKING_MONEY_VALUE;

        String str = converter.asWords(new BigDecimal(input));

        return StringUtils.capitalize(str.split("£")[0]);

    }   

<td rowspan="2" colspan="2">
         <span th:text="${MoneyUtil.getMoneyIntoWords(invoice.totalAmountAfterTax)} +'only'" />
       </td>

Error:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1011E: Method call: Attempted to call method moneyIntoWords(java.lang.Integer) on null context object

You need special syntax to call a static method in Thymeleaf:

<span th:text="${T(com.company.app.money.MoneyUtil).getMoneyIntoWords(invoice.totalAmountAfterTax)} +'only'" />

You will need to use the full qualified name of the MoneyUtil class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM