springboot事务不回滚,第一条数据总是会被插到数据库中,在启动类上加上了@EnableTransactionManagement直接开启事务支持也没效果?
@Service
public class CustomerService {
@Autowired
private CustomerRepository customerRepository;
@Transactional
public void insertTwo(){
Customer c1 = new Customer();
c1.setAge(11);
c1.setName("国宝熊猫");
c1.setTelephone("12345678901");
customerRepository.save(c1);
int x=5/0;
Customer c2 = new Customer();
c2.setAge(12);
c2.setName("太阳花");
c2.setTelephone("12345678901");
customerRepository.save(c2);
}
}