随笔都是学习笔记
随笔仅供参考,为避免笔记中可能出现的错误误导他人,请勿转载。

下面使用spring.xml进行配置事务:(注解和xml同时注入时优先使用注解)

可以发现在配置需要事务的方法时使用通配符 *,这样会使指定格式的方法注入事务,而不是指定格式的方法则不会启动事务。

<!--声明事务切入的位置-->
    <aop:config>
        <aop:pointcut id="transactionCut" expression="execution(* cn.cdulm.service.impl.*.*(..))"/>
    </aop:config>

    <!--预设什么样的方法需要使用事务-->
    <tx:advice>
        <tx:attributes>
            <!--使用通配符 * 表示后续字符-->
            <tx:method name="add*"/>    <!--所有开头是add的方法,如:add()、addUser()、addPerson()等-->
            <tx:method name="update*"/>    <!--所有开头是update的方法,如:update()、updateUser()、updatePerson()等-->
            <tx:method name="delete*"/>  <!--同理-->
            <tx:method name="get*"/>    <!--同理-->
            <tx:method name="select*"/> <!--同理-->
        </tx:attributes>
    </tx:advice>

 

posted on 2022-06-04 12:07  时间完全不够用啊  阅读(291)  评论(0编辑  收藏  举报