題外話:之從有了框架后,后臺的一切開發都變的不那么復雜了,應該說成是簡單了.對于數據訪問的開發,都是趨于接口的編程.記住,接口編程!
(一)數據訪問層開發: (importorg.springframework.orm.hibernate3.support.HibernateDaoSupport;)
(1) 創建數據訪問層接口.
(2) 創建 public class 數據訪問層實現類 extends HibernateDaoSupport implements 數據訪問層接口.
在實現類的方法(throw DataAccessException)中封裝 getHibernateTemplate().save(user) 等Spring已封裝的持久化方法.(注:如果使用Hibernate API 要用try{}catch{}自行處理導常.)
(二)業務邏輯層開發:
(1)創建業務邏輯層接口.
(2)創建 public class 業務邏輯層實現類 implements 業務邏輯層接口.
在實現類中. 引用的數據訪問層對象實例采用DI的設值方式注入
在業務邏輯方法(throw DataAccessException)中,使用數據訪問層對象實例來訪問數據庫.
*************************************
(三) Spring 配置文件
(1)配置數據源 <bean id="dataSource" ...>
(2)配置會話工廠 <bean id="sessionFactory" ...>
(3)配置事務管理器 <bean id="transactionManager" ...>
(4)配置事務代理 www.aygfsteel.com/algz/articles/163236.html
例:
<?xml version="1.0" encoding="UTF-8"?>



































<!-- 配置事務管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="userDAO" class="com.test.數據訪問層實現類">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!-- 聲明式事務代理其中方法一 -->
<bean id="userDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="userDAO" />
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean name="/login" class="業務層實現類" singleton="false">
<property name="userDAO">
<ref bean="userDAOProxy" />
</property>
</bean>
</beans>