[英]How to refer to a static method in Thymeleaf html in java?
我需要在发票 html 中使用 getMoneyIntoWords() 方法。 但是我遇到了错误。 请参阅下面的代码和错误
// 在 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>
错误:
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1011E: Method call: Attempted to call method moneyIntoWords(java.lang.Integer) on null context object
您需要特殊的语法来调用 Thymeleaf 中的 static 方法:
<span th:text="${T(com.company.app.money.MoneyUtil).getMoneyIntoWords(invoice.totalAmountAfterTax)} +'only'" />
您将需要使用MoneyUtil
class 的完整限定名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.