[英]How properly check boolean value in freemarker
所以,我試圖制定簡單的條件:
<#if documentData.isOtherInsurance>
<p>✔ Да</p>
<#else> <p>✘Нет </p></#if>
我犯了這樣的錯誤:
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]
----
所以我幾乎嘗試了一切
1)
<#if ${documentData.isOtherInsurance>} <p>✔ Да</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
是一種方法,而不是boolean
。 嘗試documentData.otherInsurance
(沒有“是”),這是 Java Bean 屬性boolean isOtherInsurance()
Java 方法自動定義的。
請注意,有時開發人員會錯誤地將此類方法聲明為Boolean isOtherInsurance()
(資本Boolean
)。 然后他們應該將其更改為Boolean getOtherInsurance()
或boolean isOtherInsurance()
。 但如果他們不這樣做,您仍然可以使用documentData.isOtherInsurance()
(請注意, ()
將調用該方法,然后將使用該方法的返回值,而不是該方法本身)。
嘗試這個:
<#if documentData.isOtherInsurance>
<@displayRow label="isOtherInsurance" value="✔ Да" />
<#else>
<@displayRow label="isOtherInsurance" value="✘Нет" />
</#if>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.