[英]Freemarker - Check Boolean value
What's the right syntax to check if the value of boolean from the form data in FreeMarker, my code: 在我的代码FreeMarker中检查表单数据中布尔值的正确语法是什么:
<#if "${form.allStores}" !false>
<@displayRow label="Receiving Stores" value="All Stores" />
<#elseif "${form.storesReceiving}" == false || "${form.storesReceiving}"?has_content>
<@displayRow label="Receiving Stores" value="No Stores"/>
<#else>
I'm getting this error: 我收到此错误:
Could not prepare mail; nested exception is freemarker.core._MiscTemplateException: Can't convert boolean to string automatically, because the "boolean_format" setting was "true,false", which is the legacy default computer-language format, and hence isn't accepted. --
Freemarker has then function since version 2.3.23: Freemarker的有那么函数自2.3.23版本:
<@displayRow label="Receiving Stores" value="${form.allStores?then('All Stores', 'No Stores')}"/>
Used like booleanExp?then(whenTrue, whenFalse)
像booleanExp?then(whenTrue,whenFalse)一样使用
Also similar to java, you can use the !
也类似于java,可以使用
!
operator to negate: 运算符否定:
<#if !form.allStores>
<@displayRow label="Receiving Stores" value="No Stores"/>
Then boolean can be only true/false so don't need elseif
: 然后,布尔值只能为true / false,因此不需要
elseif
:
<#else>
<@displayRow label="Receiving Stores" value="All Stores" />
</#if>
Called Logical NOT Operator.
称为逻辑非运算符。 Use to reverses the logical state of its operand.
用于反转其操作数的逻辑状态。 If a condition is true then Logical NOT operator will make false.
如果条件为真,则逻辑非运算符将为假。
Also prefer to use first positive condition as: 还更喜欢使用第一个阳性条件,例如:
<#if form.allStores>
<@displayRow label="Receiving Stores" value="All Stores" />
<#else>
<@displayRow label="Receiving Stores" value="No Stores"/>
</#if>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.