java Freemarker 'Collection.contains' 功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4040785/
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-10-30 04:30:13  来源:igfitidea点击:

Freemarker 'Collection.contains' functionality

javacollectionscontainsfreemarker

提问by mickthompson

From my java code I'm returning a Set<String>. The view needs to check if the Set contains a specific string.. I can't find any docs on how Freemarker can handle this.
Any idea?

从我的 java 代码我返回一个Set<String>。该视图需要检查 Set 是否包含特定字符串。我找不到有关 Freemarker 如何处理此问题的任何文档。
任何的想法?

回答by Iain

You can use seq_contains. You need FreeMarker 2.3.1

您可以使用seq_contains. 你需要 FreeMarker 2.3.1

${x?seq_contains("blue")?string("yes", "no")}

This will output yesif the sequence contains "blue".

如果序列包含“blue”,这将输出yes

And from the comments, if you want this in an if statement

从评论中,如果您想在 if 语句中使用它

<#if x?seq_contains("myString")>

Here is the doco about it Built-ins for sequences

下面是关于它的DOCO内建的序列