检查地图是否包含Freemarker中的特定密钥

Ste*_*eod 9 freemarker

在Java中:

Map<String, Object> model = new HashMap<>();
Map<String, String> items = new HashMap<>();
items.put("color", "red");
model.put("items", items);
Run Code Online (Sandbox Code Playgroud)

我现在想要在items包含密钥的渲染模板中包含一个片段color.

<#if ???? >
   the map contains a key called color
</#if>
Run Code Online (Sandbox Code Playgroud)

我该怎么替换???? 用?

glw*_*glw 13

您可以??像这样使用运算符:

<#if items['color']?? >
   the map contains a key called color
</#if>
Run Code Online (Sandbox Code Playgroud)