hibernate 用聚合函数求平均值,返回到list如何取值。
publicList<RunRecord>queryAvg(Collection<String>names,DatestartDate,DateendDate){List...
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里面字段的平均值数据。求教。。。。。 展开
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里面字段的平均值数据。求教。。。。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询