@RequestMapping(value = "test")
public String test(ModelMap mm){
Map mainMap = new HashMap();
for (int i = 0; i < 10; i++) {
Map childMap = new HashMap();
for(int j = 0 ; j < 20 ; j++){
childMap.put("key" + j, "value" + j);
}
Etuser user = new Etuser();
user.setId(i + ""); //这里已经为id赋值了
user.setLoginname("aaaaaaa");
user.setLastaccesstime(new Timestamp(System.currentTimeMillis()));
mainMap.put(user + "", childMap);
}
mm.put("mainMap", mainMap);
return "evertrip/diyquote/test";
}
//mainMap 的类型为 Map<EtUser , Map<String , String> >
<#list mainMap?keys as mainKey >
${mainKey.id}
</#list>
报错:
==> ${mainKey.id} [on line 32, column 17 in evertrip/diyquote/test.ftl]
----------
Java backtrace for programmers:
----------
freemarker.template.TemplateException: Expected hash. mainKey evaluated instead to freemarker.template.SimpleScalar on line 32, column 19 in evertrip/diyquote/test.ftl.
at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:136)
at freemarker.core.Dot._getAsTemplateModel(Dot.java:78)
如果将页面改成下面这样 , 就不会报错
我就换别的属性试试 ,都会报错 ,只要是mainKey.属性 , 就会报错
<#list mainMap?keys as mainKey >
${mainKey}
</#list>
另外。EtsUser中绝对有每个属性的get和set方法