1.关于select new map 的用法:
String hql=“select new map(s.name as name) from Student s”; List ls=session.createQuery(hql).list(); for(Map m:ls){ System.out.pringln(m.get("name")); }
返回的List 存放的是entry实体,用Map遍历便可得到里面的keySet和Values;
2.应用实例
public Map getEvaluatesOfItems() { String[] a =["zuzhiGongzuo","neirongZhenduixing","peixunQifen","shoukeXiaoguo","ziliaoZhiliang","renzhenChengdu","zhijiaoShuiping","biaodaNengli","jifaCanyuNengli","lianxiShijiNengli","fanyingNengli"]; Map[] map =new HashMap[11]; Map mm = new HashMap(); for(int i=0 ; i < a.length ; i++){ String hql = "select new map(item.${a[i]} as z,count(item.${a[i]}) as zs) from hr.training.ApplyTrainingItem item where applyTraining.id=? and item.${a[i]} is not null and item.peixunXueshi is not null group by item.${a[i]}"; List ls = ApplyTrainingItem.executeQuery(hql,[this.id]); map[i]=new HashMap(); for(Map m:ls){ map[i].put(m.get("z"),m.get("zs")); } mm.put(a[i],map[i]); } return mm; }3. 嵌套Map :
zuzhiGongzuo(nullable:true, inList:["好","较好","一般","差","较差"]) neirongZhenduixing(nullable:true, inList:["强","较强","一般","差","较差"]) peixunQifen(nullable:true, inList:["好","较好","一般","差","较差"])