简体   繁体   English

如何正确检查 freemarker 中的 boolean 值

[英]How properly check boolean value in freemarker

So, I'am trying to make simple condition:所以,我试图制定简单的条件:

<#if documentData.isOtherInsurance>
<p>&#10004 Да</p>
<#else> <p>&#10008;Нет </p></#if>

and I'm getting mistake like:我犯了这样的错误:

For "#if" condition: Expected a boolean, but this has evaluated to a method+sequence (wrapper: f.e.b.SimpleMethodModel):
==> documentData.isOtherInsurance!false  [in template "InsuranceNotification" at line 1, column 1445]

----
Tip: Maybe using obj.something instead of obj.isSomething will yield the desired value.
----

----
FTL stack trace ("~" means nesting-related):
    - Failed at: #if documentData.isOtherInsurance!false  [in template "InsuranceNotification" at line 1, column 1440]
----

So I tried almost everything所以我几乎尝试了一切

1) 1)

<#if ${documentData.isOtherInsurance>} <p>&#10004 Да</p> ...
Syntax error in template "InsuranceNotification" in line 1, column 1445:
You can't use ${...} (an interpolation) here as you are already in FreeMarker-expression-mode. Thus, instead of ${myExpression}, just write myExpression. (${...} is only used where otherwise static text is expected, i.e., outside FreeMarker tags and interpolations, or inside string literals.)

isOtherInsurance is a method, as the error messages says, not a boolean .正如错误消息所说, isOtherInsurance是一种方法,而不是boolean Try documentData.otherInsurance (no "is"), which is the Java Bean property that the boolean isOtherInsurance() Java method automatically defines.尝试documentData.otherInsurance (没有“是”),这是 Java Bean 属性boolean isOtherInsurance() Java 方法自动定义的。

Note that sometimes developers incorrectly declare such methods as Boolean isOtherInsurance() (with capital Boolean ).请注意,有时开发人员会错误地将此类方法声明为Boolean isOtherInsurance() (资本Boolean )。 Then they should change that to Boolean getOtherInsurance() , or to boolean isOtherInsurance() .然后他们应该将其更改为Boolean getOtherInsurance()boolean isOtherInsurance() But if they won't, you can still use documentData.isOtherInsurance() (note that () which will call the method, so then then the return value of the method will be used, instead of the method itself).但如果他们不这样做,您仍然可以使用documentData.isOtherInsurance() (请注意, ()将调用该方法,然后将使用该方法的返回值,而不是该方法本身)。

Try this:尝试这个:

<#if documentData.isOtherInsurance> 
    <@displayRow label="isOtherInsurance" value="&#10004 Да" />
<#else>
    <@displayRow label="isOtherInsurance" value="&#10008;Нет" />
</#if>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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