我有HashMap汽車,並且pojo Car包含屬性'engines',它又是HashMap。Freemarker HashMap循環有pojos
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;
}
Freemarker的模型
final StringWriter sw = new StringWriter();
Map model = new HashMap();
model.put("cars",theCarsMap);
Template tmpl = t.cfg.getTemplate("text.ftl");
tmpl.process(model, sw);
的Freemarker配置
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]
是否有HashMap類含POJO和另一個地圖相關的任何事情特殊處理?
粘貼* complete *錯誤消息。 – parsifal 2013-02-21 21:26:45