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); }
结果