Hibernate HQL 中的select new map 使用实例 嵌套Map
来源:互联网 发布:node服务器 编辑:程序博客网 时间:2024/06/11 16:10
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 :
- 首先要将每句HQL执行后List里面返回的Map放在一起,作为一个Map,(业务需求),取的是一个下拉列表的固定值,取出这些值和对应的个数,a数组中的这些都是下拉 列表获取的值存到数据库中的如下代码:
zuzhiGongzuo(nullable:true, inList:["好","较好","一般","差","较差"])neirongZhenduixing(nullable:true, inList:["强","较强","一般","差","较差"])peixunQifen(nullable:true, inList:["好","较好","一般","差","较差"])
,所以要用到group by column分组函数,即取到的是不同的评价和对应的个数 - 然后将Map数组依次放入最终返回的Map mm;这两步按照动态传参取出对应数据
0 0
- Hibernate HQL 中的select new map 使用实例 嵌套Map
- hql中select new map的使用
- HQL总结 Select new map()
- Hibernate中关于hibernate hql select new map的用法详解
- Hibernate调优之select new map()
- Hibernate调优之select new map()
- Hibernate调优之select new map()
- Hibernate调优之select new map()
- map的嵌套使用
- map的嵌套使用
- hibernate hql 使用实例
- C++中的map嵌套应用
- Map项目中的实例
- vector map 多层嵌套使用
- map和vector嵌套使用
- Map嵌套Map遍历
- hibernate项目的HQL(SQL区别、Select语句、返回list、map、object数组与单个对象)笔记整理
- map嵌套
- Android笔记 get方式提交数据到服务器 避免乱码 demo
- 为什么线程不能调用fork
- Git系列之多人协作
- java网络编程学习之用java编写客户/服务器程序
- 【c++程序】通过别名来交换两个数的值
- Hibernate HQL 中的select new map 使用实例 嵌套Map
- Ubuntu 14.04下安装SecureCRT 以及使用技巧
- 海泉湾海泉湾规划全文钢琴网
- linux:redhat:bash: setenforce: command not found
- 排序算法
- 6个值得推荐的Android开源框架简介
- MongoDB(三)mongoDB下载和安装
- google-play-services_lib添加不成功的解决方案
- iOS collectionview小结