如何检查 freemarker 字符串中的 null 和 empty?
How can I check null and empty both in freemarker string?
例如。
String 可以有这些值,例如 "value"、"" 或 null.
<#if str?? && str?has_content>
${str}
</#if>
如果语句不使用 TemplateModel,我可以检查 ??(null) 和 ?has_content(empty not null) 中的两个值吗?
str?has_content
returns true
如果 str
是非 null
(非缺失),并且也不是 0 长度字符串。所以你只需要 <#if str?has_content>
.
(从 TemplateModel
-s 开始,就模板而言,每个值都是 TemplateModel
。不存在非 TemplateModel
值。)
例如。 String 可以有这些值,例如 "value"、"" 或 null.
<#if str?? && str?has_content>
${str}
</#if>
如果语句不使用 TemplateModel,我可以检查 ??(null) 和 ?has_content(empty not null) 中的两个值吗?
str?has_content
returns true
如果 str
是非 null
(非缺失),并且也不是 0 长度字符串。所以你只需要 <#if str?has_content>
.
(从 TemplateModel
-s 开始,就模板而言,每个值都是 TemplateModel
。不存在非 TemplateModel
值。)