UserService { @Transactional public void save(User user) { userRepository.save(user); }  @Transactional void save(User user); @Transactional(readOnly = true) Optional<User> getById(Long userId); @Transactional User register(RegisterDto registerDto); @Transactional(readOnly = true) boolean isUsernameExist(String username, Optional<Integer> userId);  }
@Test @Transactional @Rollback(true) public void test() { User user = new User(); user.setUsername("张三"); user.setPassword("123456"); userService.save(user); assertThat(user.getId(), notNullValue()); System.out.println("user id: " + user.getId()); }