@Transactional注解

@Transactional注解保证了事务的一致性。

@Transactional
public void test(){
    TelEntity telEntity=new TelEntity();
    telEntity.setId("MIuzFUCnSDiO7XHcHeN5imkSIz5kD6GG");
    telEntity.setCallNum("18813131234");
    this.baseMapper.updateById(telEntity);
    int a =1/0;
    TelEntity telEntity1=new TelEntity();
    telEntity1.setId("CgDtiTvNA5hSShKDgkzmS3at2YGa6T3f");
    telEntity1.setCallNum("18813131234");
    this.baseMapper.updateById(telEntity1);

}

上段代码不使用@Transactional注解时,第一个更改会完成,第二个不会。如果使用注解,则两个更改都不会完成,说明使用注解后,是方法执行完成才提交事务的。

posted @ 2019-05-14 10:50  第二人生Bonnie  阅读(196)  评论(0编辑  收藏  举报