spring 的默认事务机制,当出现unchecked异常时候回滚,checked异常的时候不会回滚;
@Transactional(rollbackFor = Exception.class)
当有try catch后捕获了异常,事务不会回滚,如果不得不在service层写try catch 需要catch里面加 throw new RuntimeException 让事务回滚;
} catch (Exception e) {
e.printStackTrace();
logger.error("发生异常");
throw new RuntimeException();
}