Springboot开启事务的支持

时间:2020-08-03 23:12:15   收藏:0   阅读:70

主要分为两步

步骤一、在main方法加上@EnableTransactionManagement注解:

@SpringBootApplication
@EnableTransactionManagement//开启事物的管理支持
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

步骤二、在需要管理的方法上加上@Transactional注解:一般用在插入或者更新等方法上

@Service
public class DriverServiceImpl implements DriverService {

    @Autowired
    private DMMapper dmMapper;

    @Override
    @Transactional  //事物管理的方法,如果这个方法抛出异常,事务就会回滚
    public DM getDMById(Integer id) {
        return dmMapper.selectById(id);
    }

}

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!