本帖最后由 汪坤洋 于 2012-10-23 19:57 编辑
用spring主要是为了减少程序的耦合性,本质没什么区别,而且用spring他在配置文件可以帮你生产session工厂,简单而且耦合性低
public class DeparmentDaoImp implements DeparmentDao{
private SessionFactory mySessionFactory ;
private Session session;
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public boolean insertDep(Deparment3 deparment) {
mySessionFactory=HibernateUtil.getMySessionFactory();
session=mySessionFactory.openSession();
Transaction tx=session.beginTransaction();
session.save(deparment);
tx.commit();
session.close();
return true;
}
}这是用hibernate做的
public class MessageImpl extends HibernateDaoSupport implements MessageDao{
public boolean insertMessage(Message message) {
this.getHibernateTemplate().save(message);
return true;
}这是spring+hibernate做的
spring一般都是注入方式获取值得,所以几乎没什么依赖性!
|