在Java中,要使用键查找值,我将使用.get方法:

String value = hashmap.get(key);


在Freemarker中,显然不建议使用.get之类的东西,因为当我尝试使用它时:

<#list hash?keys as key>
    <p>${hash.get(key)}</p>
</#list>


它返回一个空异常:

freemarker.core.InvalidReferenceException: The following has evaluated to null or missing

----
FTL stack trace ("~" means nesting-related):
 - Failed at: ${hash.get(key)}  [in template "___.ftl" at line ___, column ___]
----

最佳答案

<#list hash?keys as key>
    <p>${hash[key]}</p>
</#list>


请参阅Freemarker文档中的Retrieving data from a hash部分。

09-30 14:42
查看更多