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
Freemarker 'Collection.contains' functionality
提问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内建的序列