1 回答
TA贡献1821条经验 获得超6个赞
DAO需要继承DAO extends HibernateDaoSupport
applicationContext.xml中需要注入sessionFactory
<bean id="adminManagerDAO" class="com.guigu.store.dao.AdminManagerDAO">
<!--注入SessionFactory -->
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
Session session = getHibernateTemplate().getSessionFactory().openSession();
SQLQuery query = session.createSQLQuery("select * from user_kissfly");
query.addEntity(UserKissfly.class);
query.setFirstResult(0);
//query.setFetchSize(3);
query.setMaxResults(4);
List<UserKissfly> list =query.list();
// for(UserKissfly user:list){
// System.out.println("当前用户的部门是:" + user.getDeptKissfly().getDeptname());
// }
System.out.println("查到的数据条数为:" + list.size());
session.close();
- 1 回答
- 0 关注
- 849 浏览
添加回答
举报