第1个回答 推荐于2018-05-07
public class Base{
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory()
{
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory)
{
this.sessionFactory = sessionFactory;
}
public final Session getSession()
{
return this.sessionFactory.getCurrentSession();
}
@SuppressWarnings("unchecked")
public List<T> executeQuery(String hql)
{
return (List<T>) this.getSession().createQuery(hql).list();//执行传入的sql,并返回一个list
}
}本回答被网友采纳