简体   繁体   中英

Freemarker + Java - How to “lookup” a value using key

In Java, to look up a value using the key, I would use the .get method:

String value = hashmap.get(key);

In Freemarker, apparently .get is deprecated or something, because when I try to use it:

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

it returns a null exception:

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>

See Retrieving data from a hash section in the Freemarker documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM