mybatis TDSQL 避免事务失效 双层service

2023-12-21 10:40:45

测试代码

    @Autowired
    private IProductBizService productBizService;

    @Test
    public void t4(){
        BuyItem buyItem = new BuyItem();
        buyItem.setGtin("999");
        buyItem.setExpireDate(DateUtil.offsetDay(new Date(),90));
        productBizService.test(buyItem);
    }

第一层service实现

@Service
@Slf4j
public class ProductBizServiceImpl implements IProductBizService {
    @Autowired
    private IMyTransactional myTransactional;

    @Override
    public void test(BuyItem buyItem) {
        myTransactional.saveTransactional(buyItem);
    }
}    

第二层事务层实现

@Service
public class IMyTransactionalImpl implements IMyTransactional {

    @Autowired
    private BuyItemMapper buyItemMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveTransactional(BuyItem buyItem){
        buyItemMapper.insert(buyItem);
        throw new RuntimeException("11111111111111");
    }

}


参考链接

文章来源:https://blog.csdn.net/qq56477643/article/details/135067443
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。