代码如下: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),该怎么写啊?

解决方案 »

  1.   

    这查询出来数据不止一条啊,要返回集合,而且要在jsp页面中迭代出来啊!求助!!!!
      

  2.   

    你可以在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();
    }