熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

Spring+Ibatis+事務處理

2022-06-13   來源: Java開源技術 

  applicationContextxml

  view plaincopy to clipboardprint?
    <?xml version= encoding=UTF?>

  <beans xmlns=

  xmlns:xsi=instance

  xsi:schemaLocation= beansxsd>

  <bean id=dataSource

  class=orgspringframeworkjdbcdatasourceDriverManagerDataSource>

  <property name=driverClassName>

  <value>oraclejdbcdriverOracleDriver</value>

  </property>

  <property name=url>

  <value>jdbc:oracle:thin:@::STRUTS</value>

  </property>

  <property name=username>

  <value>STRUTS</value>

  </property>

  <property name=password>

  <value>STRUTS</value>

  </property>

  </bean>

  <bean id=insertDao class=flexsamplesspringdaoInsertCl>

  <property name=sqlMapClient>

  <ref local=sqlMapClient />

  </property>

  </bean>

  <bean name=insertAction

  class=flexsamplesspringactionInsertAction>

  <property name=insertService>

  <ref bean=insertService/>

  </property>

  </bean>

  <bean id=insertService

  class=flexsamplesspringdaoInsertService>

  <property name=insertDao>

  <ref local=insertDao />

  </property>

  </bean>

  <bean id=sqlMapClient

  class=orgspringframeworkormibatisSqlMapClientFactoryBean>

  <property name=configLocation>

  <value>

  WEBINF/SqlMapConfigxml

  </value>

  </property>

  <property name=dataSource>

  <ref bean=dataSource />

  </property>

  </bean>

  <bean name=logger

  class=flexsamplesspringinterceptorLoggingInterceptor>

  </bean>

  <bean name=beanNameAutoProxy

  class=orgspringframeworkaopframeworkautoproxyBeanNameAutoProxyCreator />

  <bean id=transactionProxy parent=beanNameAutoProxy>

  <property name=beanNames>

  <list>

  <value>insertService</value>

  </list>

  </property>

  <property name=interceptorNames>

  <value>transactionInterceptor</value>

  </property>

  </bean>

  <bean id=logginProxy parent=beanNameAutoProxy>

  <property name=beanNames>

  <list>

  <value>insertDao</value>

  </list>

  </property>

  <property name=interceptorNames>

  <value>logger</value>

  </property>

  </bean>

  <bean id=transactionManager

  class=orgspringframeworkjdbcdatasourceDataSourceTransactionManager>

  <property name=dataSource>

  <ref bean=dataSource />

  </property>

  </bean>

  <bean id=transactionInterceptor class=orgspringframeworktransactioninterceptorTransactionInterceptor>

  <property name=transactionManager>

  <ref local=transactionManager />

  </property>

  <property name=transactionAttributes>

  <props>

  <prop key=*>PROPAGATION_REQUIREDException</prop>

  </props>

  </property>

  </bean>

  </beans>

  <?xml version= encoding=UTF?>

  <beans xmlns=

  xmlns:xsi=instance

  xsi:schemaLocation= beansxsd>

  <bean id=dataSource

  class=orgspringframeworkjdbcdatasourceDriverManagerDataSource>

  <property name=driverClassName>

  <value>oraclejdbcdriverOracleDriver</value>

  </property>

  <property name=url>

  <value>jdbc:oracle:thin:@::STRUTS</value>

  </property>

  <property name=username>

  <value>STRUTS</value>

  </property>

  <property name=password>

  <value>STRUTS</value>

  </property>

  </bean>

  <bean id=insertDao class=flexsamplesspringdaoInsertCl>

  <property name=sqlMapClient>

  <ref local=sqlMapClient />

  </property>

  </bean>

  <bean name=insertAction

  class=flexsamplesspringactionInsertAction>

  <property name=insertService>

  <ref bean=insertService/>

  </property>

  </bean>

  <bean id=insertService

  class=flexsamplesspringdaoInsertService>

  <property name=insertDao>

  <ref local=insertDao />

  </property>

  </bean>

  <bean id=sqlMapClient

  class=orgspringframeworkormibatisSqlMapClientFactoryBean>

  <property name=configLocation>

  <value>

  WEBINF/SqlMapConfigxml

  </value>

  </property>

  <property name=dataSource>

  <ref bean=dataSource />

  </property>

  </bean>

  <bean name=logger

  class=flexsamplesspringinterceptorLoggingInterceptor>

  </bean>

  <bean name=beanNameAutoProxy

  class=orgspringframeworkaopframeworkautoproxyBeanNameAutoProxyCreator />

  <bean id=transactionProxy parent=beanNameAutoProxy>

  <property name=beanNames>

  <list>

  <value>insertService</value>

  </list>

  </property>

  <property name=interceptorNames>

  <value>transactionInterceptor</value>

  </property>

  </bean>

  <bean id=logginProxy parent=beanNameAutoProxy>

  <property name=beanNames>

  <list>

  <value>insertDao</value>

  </list>

  </property>

  <property name=interceptorNames>

  <value>logger</value>

  </property>

  </bean>

  <bean id=transactionManager

  class=orgspringframeworkjdbcdatasourceDataSourceTransactionManager>

  <property name=dataSource>

  <ref bean=dataSource />

  </property>

  </bean>

  <bean id=transactionInterceptor class=orgspringframeworktransactioninterceptorTransactionInterceptor>

  <property name=transactionManager>

  <ref local=transactionManager />

  </property>

  <property name=transactionAttributes>

  <props>

  <prop key=*>PROPAGATION_REQUIREDException</prop>

  </props>

  </property>

  </bean>

  </beans>InsertActionjava

  view plaincopy to clipboardprint?
    package flexsamplesspringaction;

  //import javasqlTimestamp;

  //import javatextSimpleDateFormat;

  import javautilList;

  import flexsamplesspringdaoInsertService;

  import flexsamplesspringbeanUserBean;

  import flexsamplesspringinterceptorLoggingInterceptor;

  import monslogging*;

  public class InsertAction {

  //##############################################

  private Log log =LogFactorygetLog(LoggingInterceptorclass);

  private InsertService insertService;

  public InsertService getInsertService() {

  return thisinsertService;

  }

  public void setInsertService(InsertService insertService) {

  thisinsertService = insertService;

  }

  public void insertData(UserBean userList eduList pro_list) throws Exception{

  try{

  insertServiceinsertUserInfo(user edu pro_list);

  }catch (Exception e){

  (etoString());

  throw e;

  }

  }

  }

  package flexsamplesspringaction;

  //import javasqlTimestamp;

  //import javatextSimpleDateFormat;

  import javautilList;

  import flexsamplesspringdaoInsertService;

  import flexsamplesspringbeanUserBean;

  import flexsamplesspringinterceptorLoggingInterceptor;

  import monslogging*;

  public class InsertAction {

  //##############################################

  private Log log =LogFactorygetLog(LoggingInterceptorclass);

  private InsertService insertService;

  public InsertService getInsertService() {

  return thisinsertService;

  }

  public void setInsertService(InsertService insertService) {

  thisinsertService = insertService;

  }

  public void insertData(UserBean userList eduList pro_list) throws Exception{

  try{

  insertServiceinsertUserInfo(user edu pro_list);

  }catch (Exception e){

  (etoString());

  throw e;

  }

  }

  }

  InsertCljava

  view plaincopy to clipboardprint?
    package flexsamplesspringdao;

  import javautilList;

  import orgspringframeworkormibatissupportSqlMapClientDaoSupport;

  import flexsamplesspringbeanUserBean;

  public class InsertCl extends SqlMapClientDaoSupport implements InsertIn{

  public void deleteUserInfo(UserBean user){

  thisgetSqlMapClientTemplate()update(del_datauser);

  }

  public void insertBaseInfo(UserBean user){

  thisgetSqlMapClientTemplate()update(insUseruser);

  }

  public void insertDBInfo(UserBean user){

  thisgetSqlMapClientTemplate()insert(insDB_Accessuser);

  thisgetSqlMapClientTemplate()insert(insDB_SQLserveruser);

  thisgetSqlMapClientTemplate()insert(insDB_ORACLEuser);

  thisgetSqlMapClientTemplate()insert(insDB_Informixuser);

  thisgetSqlMapClientTemplate()insert(insDB_DBuser);

  thisgetSqlMapClientTemplate()insert(insDB_MySQLuser);

  thisgetSqlMapClientTemplate()insert(insDB_otherdbuser);

  }

  public void insertOSInfo(UserBean user){

  thisgetSqlMapClientTemplate()insert(insOS_Unixuser);

  thisgetSqlMapClientTemplate()insert(insOS_Linuxuser);

  thisgetSqlMapClientTemplate()insert(insOS_MVSuser);

  thisgetSqlMapClientTemplate()insert(insOS_WinXPuser);

  thisgetSqlMapClientTemplate()insert(insOS_WinNT/user);

  thisgetSqlMapClientTemplate()insert(insOS_AS/user);

  thisgetSqlMapClientTemplate()insert(insOS_otherosuser);

  }

  public void insertLangInfo(UserBean user){

  thisgetSqlMapClientTemplate()insert(insLANG_C/C++/VCuser);

  thisgetSqlMapClientTemplate()insert(insLANG_NETuser);

  thisgetSqlMapClientTemplate()insert(insLANG_COBOLuser);

  thisgetSqlMapClientTemplate()insert(insLANG_VBuser);

  thisgetSqlMapClientTemplate()insert(insLANG_JAVA/JSPuser);

  thisgetSqlMapClientTemplate()insert(insLANG_Apacheuser);

  thisgetSqlMapClientTemplate()insert(insLANG_Weblogicuser);

  thisgetSqlMapClientTemplate()insert(insLANG_Frameworkuser);

  thisgetSqlMapClientTemplate()insert(insLANG_UMLuser);

  }

  public void insertEduInfo(List edu){

  for(int i=;i<edusize();i++){

  thisgetSqlMapClientTemplate()insert(insEdueduget(i));

  }

  }

  public void insertProInfo(List pro_list){

  for(int i=;i<pro_listsize();i++){

  thisgetSqlMapClientTemplate()insert(insPropro_listget(i));

  }

  }

  }

  package flexsamplesspringdao;

  import javautilList;

  import orgspringframeworkormibatissupportSqlMapClientDaoSupport;

  import flexsamplesspringbeanUserBean;

  public class InsertCl extends SqlMapClientDaoSupport implements InsertIn{

  public void deleteUserInfo(UserBean user){

  thisgetSqlMapClientTemplate()update(del_datauser);

  }

  public void insertBaseInfo(UserBean user){

  thisgetSqlMapClientTemplate()update(insUseruser);

  }

  public void insertDBInfo(UserBean user){

  thisgetSqlMapClientTemplate()insert(insDB_Accessuser);

  thisgetSqlMapClientTemplate()insert(insDB_SQLserveruser);

  thisgetSqlMapClientTemplate()insert(insDB_ORACLEuser);

  thisgetSqlMapClientTemplate()insert(insDB_Informixuser);

  thisgetSqlMapClientTemplate()insert(insDB_DBuser);

  thisgetSqlMapClientTemplate()insert(insDB_MySQLuser);

  thisgetSqlMapClientTemplate()insert(insDB_otherdbuser);

  }

  public void insertOSInfo(UserBean user){

  thisgetSqlMapClientTemplate()insert(insOS_Unixuser);

  thisgetSqlMapClientTemplate()insert(insOS_Linuxuser);

  thisgetSqlMapClientTemplate()insert(insOS_MVSuser);

  thisgetSqlMapClientTemplate()insert(insOS_WinXPuser);

  thisgetSqlMapClientTemplate()insert(insOS_WinNT/user);

  thisgetSqlMapClientTemplate()insert(insOS_AS/user);

  thisgetSqlMapClientTemplate()insert(insOS_otherosuser);

  }

  public void insertLangInfo(UserBean user){

  thisgetSqlMapClientTemplate()insert(insLANG_C/C++/VCuser);

  thisgetSqlMapClientTemplate()insert(insLANG_NETuser);

  thisgetSqlMapClientTemplate()insert(insLANG_COBOLuser);

  thisgetSqlMapClientTemplate()insert(insLANG_VBuser);

  thisgetSqlMapClientTemplate()insert(insLANG_JAVA/JSPuser);

  thisgetSqlMapClientTemplate()insert(insLANG_Apacheuser);

  thisgetSqlMapClientTemplate()insert(insLANG_Weblogicuser);

  thisgetSqlMapClientTemplate()insert(insLANG_Frameworkuser);

  thisgetSqlMapClientTemplate()insert(insLANG_UMLuser);

  }

  public void insertEduInfo(List edu){

  for(int i=;i<edusize();i++){

  thisgetSqlMapClientTemplate()insert(insEdueduget(i));

  }

  }

  public void insertProInfo(List pro_list){

  for(int i=;i<pro_listsize();i++){

  thisgetSqlMapClientTemplate()insert(insPropro_listget(i));

  }

  }

  }

  SqlMapConfigxml

  view plaincopy to clipboardprint?
    <?xml version= encoding=UTF?>

  <!DOCTYPE sqlMapConfig

  PUBLIC ////DTD SQL Map Config //EN

  mapconfigdtd>

  <sqlMapConfig>

  <sqlMap resource=flex/samples/spring/xml/testxml/>

  </sqlMapConfig>


From:http://tw.wingwit.com/Article/program/Java/ky/201311/28520.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.