当前位置:编程学习 > JAVA >>

如何返回值的问题。求助!!!急!!

代码如下:

Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery("select goodsId,sum(goodsTotal) from Goodsinfo where outbound_id in (select outboundId from Robound where state='"
+ state + "') and createTime between '"+ time1+ "' and '"+ time2+ "'group by goodsId");

我想返回goodsId和sum(goodsTotal),该怎么写啊? --------------------编程问答-------------------- 来大神,求助啊!!! --------------------编程问答-------------------- 来大神,求助啊!!! --------------------编程问答-------------------- 你强转下试试 --------------------编程问答-------------------- 这查询出来数据不止一条啊,要返回集合,而且要在jsp页面中迭代出来啊!求助!!!! --------------------编程问答-------------------- group by前加空格 --------------------编程问答-------------------- 你可以在hql语句里把你返回的goodsId和sum(goodsTotal)放在一个list里
然后List l1=query.list();
此时 li是一个list l1.get(i)也返回一个list
思路是这样,可能也有别的好方法,暂时只知道着一个
代码如下:
public void testTest()
{
Session s=HibernateSessionFactory.getSession(); 
s.beginTransaction();
Query q=s.createQuery("select new list(u.id,u.name) from User u ");
List l=q.list();
for(int i=0;i<l.size();i++)
{
List l2=(List) l.get(i);
System.out.println(l2.get(0));//输出u.id
System.out.println(l2.get(1));//输出u.name
}
s.getTransaction().commit();
s.close();
}
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,