你若在患难之日胆怯,你的力量便微小
如果你在做一件事情之前就過分放大它的困難,這就會逐漸降低自己去做它的動機和動力,還沒開始你就已經削弱了自己的行動能力,在氣勢上就已經輸了。
不要害怕困難,勇敢的去面對問題,解決問題,你就會在氣勢上更盛。
1、什么事務
(1)事務是數據庫操作最基本單元,邏輯上一組操作,要么都成功,如果有一個失敗所有操作都失敗
(2)典型場景:銀行轉賬
- lucy 轉賬100元 給mary
- lucy少100,mary多100
2、事務四個特性(ACID)
(1)原子性
(2)一致性
(3)隔離性
(4)持久性
事務操作 事務操作
1、事務添加到JavaEE三層結構里面Service層(業務邏輯層)
2、在Spring進行事務管理操作
(1)有兩種方式:編程式事務管理和聲明式事務管理(使用)
3、聲明式事務管理
(1)基于注解方式(使用)
(2)基于xml配置文件方式
4、在Spring進行聲明式事務管理,底層使用AOP原理
5、Spring事務管理API
(1)提供一個接口,代表事務管理器,這個接口針對不同的框架提供不同的實現類
基于注解
1、在spring配置文件配置事務管理器
<!--創建事務管理器--> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!--注入數據源--> <property name="dataSource" ref="dataSource"></property> </bean>2、在spring配置文件,開啟事務注解
(1)在spring配置文件引入名稱空間
tx <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
(2)開啟事務注解
3、在service類上面(或者service類里面方法上面)添加事務注解
(1)@Transactional,這個注解添加到類上面,也可以添加方法上面
(2)如果把這個注解添加類上面,這個類里面所有的方法都添加事務
(3)如果把這個注解添加方法上面,為這個方法添加事務
參數理解
其中前兩個劃線的最重要
required
required_new
supports
總結
以上是生活随笔為你收集整理的你若在患难之日胆怯,你的力量便微小的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: L2-016. 愿天下有情人都是失散多年
- 下一篇: 2017 ICPC Naning R