[英]Freemarker - Check Boolean value
在我的代碼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. --
Freemarker的有那么函數自2.3.23版本:
<@displayRow label="Receiving Stores" value="${form.allStores?then('All Stores', 'No Stores')}"/>
像booleanExp?then(whenTrue,whenFalse)一樣使用
<#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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.