1:事务学习
事务的特性:要做就做全,要不就不做。
事务首先与 数据库是有关系的
a:原子性
c:一致性
i:隔离性
d:持久性
查询数据库的隔离级别 select @@tx_isolation
数据库中默认事务的隔离级别:REPEATABLE READ(可重复读) 默认的级别
spring中如何使用事务:
基于配置实现事务(方法已经过时)
<tx:advice>
事务的属性
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="transfer" propagation="REQUIRED"/>
<tx:method name="show*" read-only="true"/>
<tx:method name="*" rollback-for="Exception" />
</tx:attributes>
aop的配置
<aop:config>
<!--配置事务切点 -->
<aop:pointcut id="services"
expression="execution(* com.zlt.service.impl.*.*(..))" />
<aop:advisor pointcut-ref="services" advice-ref="TestAdvice" />
</aop:config>
xml完成配置
<!-- 基于xml的方式来进行配置事务 -->
<!-- advice 代表模块的意思 -->
<!-- tx代表事务 -->
<tx:advice id="TestAdvice" transaction-manager="transactionManager">
<!--配置事务传播性,隔离级别以及超时回滚等问题 -->
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="transfer" propagation="REQUIRED"/>
<tx:method name="show*" read-only="true"/>
<tx:method name="*" rollback-for="Exception" />
</tx:attributes>
</tx:advice>
<!-- aop 配置 -->
<aop:config>
<!--配置事务切点 -->
<aop:pointcut id="services"
expression="execution(* com.zlt.service.impl.*.*(..))" />
<aop:advisor pointcut-ref="services" advice-ref="TestAdvice" />
</aop:config>
注解配置
<!--使用注释事务
<tx:annotation-driven transaction-manager="transactionManager" />
-->