我有 HashMap 汽车,而 pojo Car 包含属性“engines”,它又是 HashMap。
public class Car implements Serializable{
private Long id;
private String name;
private Map<Long,Engine> engines = new HashMap<>();
..
..
}
public class Engine implements Serializable{
private Long id;
private String name;
}
自由标记模型
final StringWriter sw = new StringWriter();
Map model = new HashMap();
model.put("cars",theCarsMap);
Template tmpl = t.cfg.getTemplate("text.ftl");
tmpl.process(model, sw);
自由标记配置
cfg = new Configuration();
cfg.setCacheStorage(new freemarker.cache.MruCacheStorage(20, 250));
cfg.setClassForTemplateLoading(getClass(), ".");
cfg.setObjectWrapper(new DefaultObjectWrapper());
模板代码:
<#assign rKeys = cars?keys>
<#list rKeys as rKey>
Car Details:${cars[rKey].getName()}\n
--------------------------------------------------\n
<#assign engines = cars[rKey].getEngines()>
<#assign tKeys = engines?keys>
<#list tKeys as tKey>
------------------Engine Details-----------------\n
Name: ${engines[tKey].getName()}\n
</#list>
</#list>
我收到以下错误:
有问题的指令:
${cars[rKey].getName()} [on line 3, column 18 in text.ftl]
是否有任何与包含 pojos 和另一个 Map 的 HashMap 相关的特殊处理?