2019-05-25
声明式事务
<tx:annotation-driven transaction-manager="" />
RoleServiceImpl--insertRole
@Transactional(propagation = Propagation.REQUIRES_NEW,isolation=Isolation.READ_COMMITTED)
public int insertROle(Role role){
return roleMapper.insertRole(role);
}
<!--开启基于注解的事务,使用xml配置形式的事务,-->
<aop:config>
<!--切入点表达式-->
<aop:pointcut id="txPoint" expression="execution(* com.atguigu.crud.service.*.*(..))"/>
<!--配置事务增强-->
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"/>
</aop:config>
<!--配置事务增强,事务如何切入-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!--所有方法都是事务方法-->
<tx:method name="*"/>
<!--以get开始的所有方法-->
<tx:method name="get*" read-only="true"/>
<tx:method name="edit*" propagation="REQUIRED" read-only="true"/>
</tx:attributes>
</tx:advice>
网友评论