MISBoot快速开发平台

事务控制管理

一、在service实现类中的方法上增加 @Transactional 注解即可

事务回滚
@Transactional
    @Override
    public int executeUpdate(MatRepertoryEnter matRepertoryEnter, MatRepertory matRepertory) {
        Integer integer = 0, integerm = 0;
        matRepertoryEnter.setUuid("09DC9839641D45F6AC06FE2B281229D2");
        matRepertoryEnter.setNumber("1");
        integer = oaRepertoryEnterMapper.executeUpdate(matRepertoryEnter);
        matRepertory.setUuid("8715a07f34084d58b2883140d1cec6aa");
        matRepertory.setRnumber("2");
        integerm = matRepertoryMapper.executeUpdate(matRepertory);
        Integer i = 1 / 0;
        return integer == 1 && integerm == 1 ? 1 : 0;
    }

二、如果使用try catch事务需手动回滚

try catch事务回滚
@Transactional
    @Override
    public int executeUpdate(MatRepertoryEnter matRepertoryEnter, MatRepertory matRepertory) {
        Integer integer = 0, integerm = 0;
        try {
            matRepertoryEnter.setUuid("09DC9839641D45F6AC06FE2B281229D2");
            matRepertoryEnter.setNumber("1");
            integer = oaRepertoryEnterMapper.executeUpdate(matRepertoryEnter);
            matRepertory.setUuid("8715a07f34084d58b2883140d1cec6aa");
            matRepertory.setRnumber("2");
            integerm = matRepertoryMapper.executeUpdate(matRepertory);
            Integer i=1/0;
        } catch (Exception e) {
            e.printStackTrace();
            // 使用 try catch 手动回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return integer == 1 && integerm == 1 ? 1 : 0;
    }
QQ在线咨询
客服 QQ
251122361
微信/手机
18973127736
办公电话
0731-89565588