zoukankan      html  css  js  c++  java
  • springboot如何使用事物注解方式

    1.在启动类Application中添加注解@EnableTransactionManagement 

    import tk.mybatis.spring.annotation.MapperScan;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.transaction.annotation.EnableTransactionManagement;
    
    @SpringBootApplication
    @EnableTransactionManagement //开启书屋管理注解模式 最新的版本可以省略
    @MapperScan("com.xz.springboot.mapper") //扫描该包下所有的接口并为该接口生成实现类
    public class Springboot01Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Springboot01Application.class, args);
        }
    
    }

    2.在业务层添加@Transactional

    import com.xz.springboot.bean.User;
    import com.xz.springboot.mapper.UserMapper;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    import java.util.List;
    
    @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;
        }
    }
  • 相关阅读:
    python开发必备:virtualenv虚拟环境(自用)
    JavaScript经典实例
    javascript事件驱动及事件处理
    在HTML网页中嵌入脚本的方式
    JavaScript数据结构
    JavaScript语言调试技巧
    CSS+DIV布局
    在HTML文档中应用CSS
    CSS常用属性
    定义CSS
  • 原文地址:https://www.cnblogs.com/sitian2050/p/11824850.html
Copyright © 2011-2022 走看看