日期:2014-05-16  浏览次数:20347 次

Hibernate封装数据返回Json
public List getAllContentClickCount() {
        final String query = "select b.smsContentId as ContentId,count(*) as ClickCount from SmsContentClickLog b left join SmsContent a on b.smsContentId=a.id where a.deleted=1 group by b.smsContentId";
        List list = (List)this.getHibernateTemplate().execute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                return session.createSQLQuery(query).addScalar("ContentId", Hibernate.INTEGER).addScalar("ClickCount",Hibernate.INTEGER).setResultTransformer(new AliasToBeanResultTransformer(SmsCoutentCilckCount.class)).list();
            }
        });
        return list;
    }

返回结果:['ClickCount':12,'ClickCount':23]