@Test public void testSave() { User user = newInstence(); userService.save(user); assertThat(user.getId(), not(0)); }
@Transactional(propagation = Propagation.REQUIRED) public void save(User user) { if (user.getId() == 0 && this.findByEmail(user.getEmail()) != null) { throw new DBException("已经存在相同的邮箱"); } else { userDao.save(user); } }
UserService { @Transactional(propagation = Propagation.REQUIRED) public void save(User user) { if (user.getId() == 0 && this.findByEmail(user.getEmail()) != null) { throw new DBException("已经存在相同的邮箱"); } else { userDao.save(user); } } }
UserService { @Transactional(propagation = Propagation.REQUIRED) public void save(User user) { if (user.getId() == 0 && this.findByEmail(user.getEmail()) != null) { throw new DBException("已经存在相同的邮箱"); } else { userDao.save(user); } }  }
UserService { @Transactional(propagation = Propagation.REQUIRED) public void save(User user) { if (user.getId() == 0 && this.findByEmail(user.getEmail()) != null) { throw new DBException("已经存在相同的邮箱"); } else { userDao.save(user); } }  @Transactional(propagation = Propagation.REQUIRED) void save(User user); @Transactional(propagation = Propagation.REQUIRED) User update(User user); User findByEmail(String email); User findById(int id); @Transactional void updateNickname(User user, String nickName); }
UserService { @Transactional(propagation = Propagation.REQUIRED) public void save(User user) { if (user.getId() == 0 && this.findByEmail(user.getEmail()) != null) { throw new DBException("已经存在相同的邮箱"); } else { userDao.save(user); } }  @Transactional(propagation = Propagation.REQUIRED) void save(User user); @Transactional(propagation = Propagation.REQUIRED) User update(User user); User findByEmail(String email); User findById(int id); @Transactional void updateNickname(User user, String nickName);  }