Springboot MySQL 事务回滚

1、properties配置:

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect

2、Service注解

	@Transactional(rollbackOn = {IllegalArgumentException.class})
	public void save(User user) {
		userDao.save(user);
		if (user.getF_user_name().equals("houjiaqi")) {
            throw new IllegalArgumentException("houjiaqi 已存在,数据将回滚");
        }
	}

3、需要注意的是,虽然回滚了,但是自增长id是不会回滚的

猜你喜欢

转载自blog.csdn.net/Dopamy_BusyMonkey/article/details/81349252