要迭代哈希映射,可以使用hash built-in来访问Map的值和键。现在我想对键进行操作,即上键来键(这是一个字符串):
<#assign keys = formats?keys>
<#list keys as key>
${key.toUpperCase()} = ${formats[key].getFileName()}
</#list>
但是我收到了错误
For "." left-hand operand: Expected a hash, but this has evaluated to a string (wrapper: f.t.SimpleScalar):
==> key [in template "src/main/resources/test.ftl" at line 41, column 69]
----
FTL stack trace ("~" means nesting-related):
- Failed at: ${key.toString().toUpperCase()} [in template "src/main/resources/test.ftl" at line 41, column 67]
----
如何提示如何在模板中将密钥(小写)设置为大写?或者如何将哈希转换为字符串?
答案 0 :(得分:2)
在FreeMarker中,隐藏了许多基本类(例如String
,Number
,List
等)的Java API。而不是他们的API-s,你应该使用所谓的&#34;内置插件&#34;,就像在这种情况下:key?upper_case
。 (另见:http://freemarker.org/docs/ref_builtins.html)