我正在尝试访问一个对象,该对象在我的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]



  从序列中检索数据
  这与散列相同,但是您只能使用方括号语法,并且括号中的表达式必须计算为数字,而不是字符串。例如,要获取示例数据模型的第一个动物的名称(请记住,第一个动物的编号是0,而不是1):animals [0] .name

关于java - 如何在FTL(Freemarker)中访问列表列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52360913/

10-14 12:45
查看更多