日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring mvc注解方式使用事务回滚

發(fā)布時間:2024/10/12 javascript 76 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring mvc注解方式使用事务回滚 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

項目名:1ma1ma

jdbc.xml

? ? <bean ?id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"?
? ? ? ? ? ?p:driverClassName="${jdbc.driverClassName}"
? ? ? ? ? ?p:url="${jdbc.url}"
? ? ? ? ? ?p:username="${jdbc.username}"
? ? ? ? ? ?p:password="${jdbc.password}"
? ? ? ? ? ?p:maxActive="${jdbc.pool-size}"
? ? ? ? ? ?p:minEvictableIdleTimeMillis="600000" p:timeBetweenEvictionRunsMillis="900000"
? ? ? ? ? ?p:removeAbandoned="true" p:logAbandoned="true" p:removeAbandonedTimeout="120"
? ? ? ? ? ?p:maxWait="5000"
? ? />

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> ?
? ? ? ? <property name="dataSource"> ?
? ? ? ? ? ? <ref local="dataSource" /> ?
? ? ? ? </property> ?
? ? </bean> ?
? ? <tx:annotation-driven transaction-manager="transactionManager" />
? ? <context:component-scan base-package="com.yaoma.*"> ??
? ? ? ? <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> ??
? ? </context:component-scan> ?



servlet-context.xml


? ? <context:component-scan base-package="com.yaoma.*" > ??
? ? ? ? <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> ??
? ? ? ? <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" /> ? ?
? ? </context:component-scan> ?



? ? @Transactional
? ? public int delete(String IMGroupID, String userid) throws Exception {
? ? ? ? //依照IMGroupID和userid更新相應的Groups表內容
? ? ? ? int is_return = Groups_Dao.IsDeleted_Groups(IMGroupID, userid, 0);
? ? ? ? if (is_return == 0) {
? ? ? ? ? ? throw new RuntimeException("is_return is 0;");
? ? ? ? }


? ? ? ? //去環(huán)信上刪除相應的數據
? ? ? ? String hx_return = HX_Service.delete_group(IMGroupID);
? ? ? ? if (hx_return == null) {
? ? ? ? ? ? throw new RuntimeException("hx_return is null");
? ? ? ? }
? ? ? ? return Integer.parseInt(hx_return);
? ? }



? ? @Transactional注解標簽

由于在執(zhí)行中,所以使用RuntimeException進行異常拋出,類中不能使用try捕捉異常,直接throws Exception拋出異常

如執(zhí)行時使用Exception拋出異常,則回滾無效

轉載于:https://www.cnblogs.com/llguanli/p/6767259.html

總結

以上是生活随笔為你收集整理的Spring mvc注解方式使用事务回滚的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。