java - Freemarker - 检查 boolean 值

标签 java boolean freemarker

从 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/

相关文章:

java - 为什么要在 App Engine 上设置系统属性(例如 java.vm.specation.version)?

Java:CardLayout在卡片之间切换

sql - 对于 PostgreSQL 中的 boolean 数据类型,输出 "yes/no"而不是 "t/f"

java - Freemarker 嵌套列表

java - 删除 Freemarker 模板中的 HTML 标签

java - JFileChooser设置目录

java - 是否有任何库可以让我们在 recyclerview 中获得选框效果(例如 hotstar vip 页面滚动图像)?

c - 如何快速评估大量 boolean AND?

ruby - 在 Padrino/Datamapper 应用程序中读取 boolean 值时出现问题

java - 使用 spring mvc 的 freemarker 的第一步