从我的代码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>
我收到此错误:
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. --
答案 0 :(得分:1)
类似于Java,使用!
操作数取反:
<#if !form.allStores>
<@displayRow label="Receiving Stores" value="No Stores"/>
那么布尔值只能是true / false,所以不需要elseif
:
<#else>
<@displayRow label="Receiving Stores" value="All Stores" />
</#if>
还喜欢将第一个阳性条件用作:
<#if form.allStores>
<@displayRow label="Receiving Stores" value="All Stores" />
<#else>
<@displayRow label="Receiving Stores" value="No Stores"/>
</#if>
或者简单地使用freemarker的then function:
<@displayRow label="Receiving Stores" value="${form.allStores?then('All Stores', 'No Stores')}"/>
此内置功能自FreeMarker 2.3.23开始存在。
像booleanExp?then(whenTrue,whenFalse)一样使用