事务ACID原则:
思考:
为什么需要事务?
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
<!--配置声明式事务--> <bean id="transationManger" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!--结合AOP实现事务的置入--> <!--配置事务的类--> <tx:advice id="txadvice" transaction-manager="transationManger"> <!--给那些方法配置事务--> <tx:attributes> <tx:method name="addUser" propagation="REQUIRED"/> <tx:method name="delectUser" propagation="REQUIRED"/> <tx:method name="update" propagation="REQUIRED"/> <tx:method name="query" read-only="true"/> <tx:method name="*" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <!--配置事务切入--> <aop:config> <aop:pointcut id="txPointCut" expression="execution(* com.shuang.mapper.*.*(..))"/> </aop:config>