美文网首页
66.Seata案例-异常模拟

66.Seata案例-异常模拟

作者: LANSHENGYANG | 来源:发表于2020-06-12 18:32 被阅读0次

异常模拟

@Override
@Transactional
public void reduceInventory(Integer pid, Integer number) {
    Product product = productDao.findById(pid).get();
    if (product.getStock() < number) {
        throw new RuntimeException("库存不足");
    }
    int i = 1 / 0;
    product.setStock(product.getStock() - number);
    productDao.save(product);
}

相关文章

网友评论

      本文标题:66.Seata案例-异常模拟

      本文链接:https://www.haomeiwen.com/subject/cquntktx.html