码迷,mamicode.com
首页 > 编程语言 > 详细

springboot中添加事务注解

时间:2019-11-16 17:37:20      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:map   list   main   auto   integer   nbsp   static   public   bsp   

1.首先在service层中的方法前添加@Transactional

@Service
public class UserService {
        @Autowired
        private UserMapper userMapper;

        public List<User> queryAll(){
            System.out.println("热部署");
            return userMapper.findAll();
        }
    @Transactional
    public void deleteById(Integer id) {
           userMapper.deleteById(id);
         //  int c=10/0;
    }
}

2.在springboot的启动中添加注解@EnableTransactionManagement

@SpringBootApplication
@EnableTransactionManagement //开启事务管理注解模式 最新的版本可以省略
@MapperScan("com.xz.springboot.mapper") //扫描该包下所有的接口并为该接口生成实现类
public class Springboot01Application {

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

}

 

springboot中添加事务注解

标签:map   list   main   auto   integer   nbsp   static   public   bsp   

原文地址:https://www.cnblogs.com/sitian2050/p/11872408.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!