Hibernate hql avg查询数据返回到list里面如何取出字段的avg值。
public List<RunRecord> queryAvg(Collection<String> names , Date startDate,Date endDate){
List<RunRecord> rets = new ArrayList<RunRecord>();
List<RunRecord> list = new ArrayList<RunRecord>();
Session session = HibernateUtils.create();
for(String str:names){
String hql = "select avg(activePowerAvg),avg(reactivePwerAvg),max(activePowerMax) from RunRecord rr where rr.name=:name and rr.insertDate>startDate and rr.insertDate<:endDate";
Query query = session.createQuery(hql);
query.setString("name", str);
query.setTimestamp("startDate" , startDate);
query.setTimestamp("endDate" , endDate);
list = query.list();
rets = query.addAll(list);
}
HibernateUtils.closeSession(session);
return rets;
}
调用的时候我这么 写的
List<RunRecord> records = recordDao.queryAvg(names.keySet(),startTime,endTime);
for(int i=0;i<records.size();i++){
system.out.println(records.get(i))
}返回的是一个类似对象的字符串 [Ljava.lang.Object;@10ec102 我就想得到返回list里面字段的平均值数据。求教。。。。。
...全文
相关推荐
hibernate 中HQL语句查询学习笔记
### Hibernate中HQL语句查询学习笔记#### HQL基础**HQL**(Hibernate Query Language)是Hibernate框架推荐使用的查询语言,它提供了一种面向对象的方式来查询数据库
Hibernate HQL教程
### Hibernate HQL 教程知识点总结#### 1.1 HQL基础##### 1.1.1 默认数据库表和数据- **介绍**: 本文档以`joblog`数据库为例,该数据库包含三个表:`student
Hibernate HQL查询.docx
**List 集合** - 当查询结果为多个对象时,通常使用 `list()` 方法返回一个 List 集合。
Hibernate查询语言(HQL)
这种特性使得 HQL 成为了在 Hibernate 中执行数据查询的理想选择。
hibernate查询语句--HQL
综上所述,HQL 提供了一种强大而灵活的方式来查询 Hibernate 中的数据。通过掌握这些基本概念和技巧,开发人员可以轻松地构建复杂的数据查询逻辑,并有效地管理应用程序中的数据访问层。


