美文网首页
【spring】spring事务

【spring】spring事务

作者: giraffecode9668 | 来源:发表于2019-05-28 00:34 被阅读0次

    2019-05-25

    声明式事务

    使用注解定义事务 @Transactional
    <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配置事务
    <!--开启基于注解的事务,使用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>
    

    相关文章

      网友评论

          本文标题:【spring】spring事务

          本文链接:https://www.haomeiwen.com/subject/pnsazqtx.html