在HQL中将查询结果封装入实例化对象

来源:互联网 发布:育碧优化好ea不坑钱 编辑:程序博客网 时间:2024/06/03 11:18
public void avg3(){        //使用DecimalFormat方法对Double数值进行格式化        DecimalFormat df=new DecimalFormat("0.00");             session=HibernateUtil.getSession();//聚合函数        hql="select new entity.DeptSalary(e.dept.deptName,avg(e.sal)) from Emp e group by e.dept.deptName";        List<DeptSalary> dsList=session.createQuery(hql).list();        for(DeptSalary ds:dsList){            System.out.print(ds.getDeptName()+" : ");                       System.out.print(df.format(ds.getSalary()));            System.out.println();        }        HibernateUtil.closeSession();    }
0 0
原创粉丝点击