//继承HibernateDaoSupport父类 //带hql查询语句和objs参数对象数组 public List<T> findByHql(final String hql,final Object[]objs){ return (List)getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query=session.createQuery(hql); if(objs!=null){ for(int i=0;i<objs.length;i++){ query.setParameter(i,objs[i]); } } return (List<T>)query.list(); } }); } //调用查询方法 public List<NewsComment> findByNewsId(Long newsId) { final String hql = "from NewsComment n where n.news.newsId=?"; Object[] params ={newsId}; return findByHql(hql, params); }