从 FreeMarker 中的表单数据中检查 boolean 值是否正确的语法是什么,我的代码:
<#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. --
最佳答案
Freemarker 有 then function从 2.3.23 版开始:
<@displayRow label="Receiving Stores" value="${form.allStores?then('All Stores', 'No Stores')}"/>
Used like booleanExp?then(whenTrue, whenFalse)
也类似于java,可以使用!
operator否定:
<#if !form.allStores>
<@displayRow label="Receiving Stores" value="No Stores"/>
那么 boolean 值只能是真/假,所以不需要 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.
也喜欢使用第一个肯定条件:
<#if form.allStores>
<@displayRow label="Receiving Stores" value="All Stores" />
<#else>
<@displayRow label="Receiving Stores" value="No Stores"/>
</#if>
关于java - Freemarker - 检查 boolean 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53190387/