本文主要是介绍mybatis TDSQL 避免事务失效 双层service,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
测试代码
@Autowiredprivate IProductBizService productBizService;@Testpublic 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 {@Autowiredprivate IMyTransactional myTransactional;@Overridepublic void test(BuyItem buyItem) {myTransactional.saveTransactional(buyItem);}
}
第二层事务层实现
@Service
public class IMyTransactionalImpl implements IMyTransactional {@Autowiredprivate BuyItemMapper buyItemMapper;@Override@Transactional(rollbackFor = Exception.class)public void saveTransactional(BuyItem buyItem){buyItemMapper.insert(buyItem);throw new RuntimeException("11111111111111");}}
参考链接
这篇关于mybatis TDSQL 避免事务失效 双层service的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!