• 测试@Transactional


    https://www.toutiao.com/a7025459579328741924/?log_from=8a8f5b7f5de1a_1640749541015

    前提使用springboot 2.1.7 Mybatis-plus

    测试1:测试前displayd = 1 ==>测试后任为1 发生了回滚(未进行try-catch)

        @Override
        @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
        public void updateFactory(String factoryId) {
            lambdaUpdate().eq(FactoryPO::getId, factoryId)
                    .set(FactoryPO::getDisplayd, Boolean.FALSE)
                    .update();
            String str = null;
            str.equals(factoryId);
        }

    结果:

    测试2:测试前displayd = 1 ==>测试后为0 未发生了回滚(进行try-catch)

        @Override
        @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
        public void updateFactory(String factoryId) {
            lambdaUpdate().eq(FactoryPO::getId, factoryId)
                    .set(FactoryPO::getDisplayd, Boolean.FALSE)
                    .update();
            String str = null;
            try{
                str.equals(factoryId);
            }catch (Exception e){
                e.printStackTrace();
            }
        }

    结果:

    测试3:测试前displayd = 1, deleted = 0, updateFactory方法中调deleteFactory方法,displayd和deleted没有修改,回滚

    @Override
        @Transactional(rollbackFor = Exception.class)
        public void updateFactory(String factoryId) {
            lambdaUpdate().eq(FactoryPO::getId, factoryId)
                    .set(FactoryPO::getDisplayd, Boolean.FALSE)
                    .update();
            deleteFactory(factoryId);
        }
    
        @Override
        public void deleteFactory(String factoryId) {
            removeById(factoryId);
            String str = null;
            str.equals(factoryId);
        }

    结果

    测试4:测试前displayd = 1, deleted = 0, updateFactory方法中调deleteFactory方法,displayd = 0,deleted=1,未回滚

        @Override
        public void updateFactory(String factoryId) {
            lambdaUpdate().eq(FactoryPO::getId, factoryId)
                    .set(FactoryPO::getDisplayd, Boolean.FALSE)
                    .update();
            deleteFactory(factoryId);
    } @Override @Transactional(propagation
    = Propagation.REQUIRED, rollbackFor = Exception.class) public void deleteFactory(String factoryId) { removeById(factoryId); String str = null; str.equals(factoryId); }

    结果

  • 相关阅读:
    python读写文件模式的区别
    【Terminal】终端美化
    【Macintosh】MAC基本使用
    【MySQL】使用mysql数据量统计
    软件测试自学还是报班好?需要掌握哪些技能?
    400页共计800道软件测试面试真题汇总!超全干货
    软件测试是吃青春饭的吗?30岁后软件测试该何去何从?
    leetcode_链表操作1
    [数据库系列之MySQL] Mysql整体架构浅析一
    Ubuntu 配置谷歌Android Test Station
  • 原文地址:https://www.cnblogs.com/zcjyzh/p/15744401.html
Copyright © 2020-2023  润新知