• 测试@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); }

    结果

  • 相关阅读:
    路由器漏洞调试的一些技巧
    路由器漏洞挖掘利用的一些基础知识
    windows 利用环境变量%PATH%中目录可写提权

    python super原理,不是指父类
    regexp盲注的一些改进
    阿里规范
    阿里规范
    工具类
    Timer 使用 (一)
  • 原文地址:https://www.cnblogs.com/zcjyzh/p/15744401.html
Copyright © 2020-2023  润新知