当前位置:首页 > 资讯 > info6 > 正文

懒得笔记6 spring hibernate template

发表于: 2015-08-16   作者:chen_xinjia   来源:转载   浏览:
摘要: 不用写trycatchfinally userDAOimplpackagecom.bjsxt.dao.impl; importjavax.annotation.Resource; importorg.hibernate.Session; importorg.springframework.orm.hibernate3.HibernateTemplate; importorg.springfr

不用写try catch finally

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
		<property name="sessionFactory" ref="sessionFactory"></property>
	</bean>

userDAOimpl

package com.bjsxt.dao.impl;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.bjsxt.dao.UserDAO;
import com.bjsxt.model.User;

@Component("u") 
public class UserDAOImpl implements UserDAO {

	private HibernateTemplate hibernateTemplate;

	

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}


	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}



	public void save(User user) {
		
			hibernateTemplate.save(user);
			
		//throw new RuntimeException("exeption!");
	}

}

在impl里不再需要sessionFactory


懒得笔记6 spring hibernate template

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号