java freemarker 模板检查序列是否为空

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27991964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:46:22  来源:igfitidea点击:

freemarker templates check if sequence is empty

javafreemarker

提问by SeanPlusPlus

I would like to check if a sequence is empty in a freemarker template.

我想检查 freemarker 模板中的序列是否为空。

This snippet works to check if a sequence containsa value:

此代码段用于检查序列是否包含值:

<#if node.attachments?seq_contains("blue")>
  <pre>hello</pre>
</#if>

However, if node.attachmentsis empty i would like to do something else.

但是,如果node.attachments是空的,我想做其他事情。

That is the syntax for this?

这是这个的语法吗?

回答by Zipper

Try:

尝试:

<#if node.attachments?size != 0>

Or:

或者:

<#if node.attachments?has_content>