[英]How to use a method that returns boolean in ftl's <#if> statement
So, in Java, you can call some methods that return Boolean
on a String
, for example, string.startsWith("substring")
.因此,在 Java 中,您可以调用一些在
String
上返回Boolean
的方法,例如string.startsWith("substring")
。 I want to use this in the ftl file, but for some reason this does not work.我想在 ftl 文件中使用它,但由于某种原因这不起作用。
<#if string.startsWith("substring")></#if>
I am pretty new to ftl, I just started learning it today, but, why this does not work?我是 ftl 的新手,我今天才开始学习它,但是,为什么这不起作用? In java,
if
statement accepts Boolean
, startsWith
method returns Boolean
, so, what is the problem here?在 java 中,
if
语句接受Boolean
, startsWith
方法返回Boolean
,那么,这里有什么问题?
Error is: Expected a hash, but this has evaluated to a string
.错误是:
Expected a hash, but this has evaluated to a string
。 I do not get it, how can if
statement receive a hash??我不明白,
if
语句怎么能收到hash? Should not it receive a Boolean
?它不应该收到
Boolean
吗?
Most Java String methods are hidden in FTL.大多数 Java String 方法都隐藏在 FTL 中。 You have to instead use an FTL builtin.
您必须改为使用内置的 FTL。 In your case, use
在你的情况下,使用
<#if string?starts_with("substring")></#if>
See documentation请参阅文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.