如何访问 FTL 中的列表映射(Freemarker)
How to Access Map of List in FTL(Freemarker)
我正在尝试访问一个对象,该对象在我的 ftl 文件中具有字符串、列表和映射类型的字段。
Configuration configuration = prepareConfiguration();
configuration.setClassForTemplateLoading(this.getClass(), "/");
Map<String, Object> mapVal = new HashMap<String, Object>();
mapVal.put("package", packageListing);
Template template = configuration.getTemplate("listing/listing.ftl");
StringWriter stringWriter = new StringWriter();
template.process(mapVal, stringWriter);
String string = stringWriter.toString();
这是我的代码片段。我有一个
类型的字段
Map<String, ArrayList<ArrayList<Object>>>
在我的 packageListing 对象中。我正在尝试访问对象列表。 Java.
中的 Map.get(Key).get(index)
在Freemarker中getting a value from a map or array也是一样,使用方括号:
packageListing[key][index]
Retrieving data from a sequence
This is the same as for hashes, but you can use the square bracket syntax only, and the expression in the brackets must evaluate to a number, not a string. For example to get the name of the first animal of the example data-model (remember that the number of the first item is 0, not 1): animals[0].name
我正在尝试访问一个对象,该对象在我的 ftl 文件中具有字符串、列表和映射类型的字段。
Configuration configuration = prepareConfiguration();
configuration.setClassForTemplateLoading(this.getClass(), "/");
Map<String, Object> mapVal = new HashMap<String, Object>();
mapVal.put("package", packageListing);
Template template = configuration.getTemplate("listing/listing.ftl");
StringWriter stringWriter = new StringWriter();
template.process(mapVal, stringWriter);
String string = stringWriter.toString();
这是我的代码片段。我有一个
类型的字段Map<String, ArrayList<ArrayList<Object>>>
在我的 packageListing 对象中。我正在尝试访问对象列表。 Java.
中的Map.get(Key).get(index)
在Freemarker中getting a value from a map or array也是一样,使用方括号:
packageListing[key][index]
Retrieving data from a sequence This is the same as for hashes, but you can use the square bracket syntax only, and the expression in the brackets must evaluate to a number, not a string. For example to get the name of the first animal of the example data-model (remember that the number of the first item is 0, not 1): animals[0].name