天天看点

springboot中事务的使用

一:启动 类上添加注解

@SpringBootApplication
@EnableTransactionManagement
public class SpringbootMybatisDemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringbootMybatisDemoApplication.class, args);
        System.out.println("-------------------启动成功--------------------");
    }
}      

二:在要 使用的方法上加注解,或者在 Controller类上添加 注解

/**
     * @Description:
     * @Param:
     * @return:
     * @Author: caidingnu
     * @Date: 2019/4/13
     */
    @RequestMapping("add")
    @Transactional
    public int add() {
        int a = userinfoDao.insertSelective(new UserinfoPo("李白", "11"));
        int b = userinfoDao.insertSelective(new UserinfoPo("李白", "22"));
        int c = userinfoDao.insertSelective(new UserinfoPo("李白", "33"));
        int e = userinfoDao.insertSelective(new UserinfoPo("李白", "5588888888888888"));
        int f = userinfoDao.insertSelective(new UserinfoPo("李白", "66"));
        int g = userinfoDao.insertSelective(new UserinfoPo("李白", "77"));

        int result = a + b + c + e + f + g;


        return result;
    }      

三:数据库

继续阅读