You can use the .dataModel
special variable like this:
<#list .data_model?keys as prop>
${prop} - ${.data_model[prop]}
</#list>
See the freemarker documentation.
Question
The map in JAVA CODE
Map dataMap = new HashMap();
dataMap.("key1","value1");
dataMap.("key2","value2");
dataMap.("key3","value3");
dataMap.("key4","value4");
and freemarker
template.process(dataMap, out);
In the FTL
<#list dataMap.keySet() as k>
<span>${k}:</span><span>dataMap[k]</span>
</#list>
I got the error: freemarker.core.InvalidReferenceException: Expression dataMapis undefined
So how can I get the value of "key1","key2","key3" and "value1","value2","value3" in the FTL? I tried to use "rootMap",".main",".vars" to replace "dataMap".All invalid.
Solution
You can use the .dataModel
special variable like this:
<#list .data_model?keys as prop>
${prop} - ${.data_model[prop]}
</#list>
See the freemarker documentation.