diff --git a/src/main/java/com/test/demo/service/impl/AuthServiceImpl.java b/src/main/java/com/test/demo/service/impl/AuthServiceImpl.java index 95e3c24..dea05d0 100644 --- a/src/main/java/com/test/demo/service/impl/AuthServiceImpl.java +++ b/src/main/java/com/test/demo/service/impl/AuthServiceImpl.java @@ -23,7 +23,6 @@ import com.test.demo.vo.LoginVo; import com.test.demo.vo.UserVo; import lombok.RequiredArgsConstructor; import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.dao.DuplicateKeyException; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -109,7 +108,7 @@ public class AuthServiceImpl implements AuthService { user.setStatus(UserStatusEnum.NORMAL); try { userService.save(user); - } catch (DuplicateKeyException | DataIntegrityViolationException ex) { + } catch (DataIntegrityViolationException ex) { throw new BizException(ResultCode.CONFLICT, "用户名已存在"); } } diff --git a/src/main/java/com/test/demo/service/impl/UserServiceImpl.java b/src/main/java/com/test/demo/service/impl/UserServiceImpl.java index 5b22d63..a57b7b8 100644 --- a/src/main/java/com/test/demo/service/impl/UserServiceImpl.java +++ b/src/main/java/com/test/demo/service/impl/UserServiceImpl.java @@ -22,7 +22,6 @@ import com.test.demo.vo.UserVo; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.dao.DuplicateKeyException; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -73,7 +72,7 @@ public class UserServiceImpl extends ServiceImpl impleme entity.setStatus(UserStatusEnum.NORMAL); try { save(entity); - } catch (DuplicateKeyException | DataIntegrityViolationException ex) { + } catch (DataIntegrityViolationException ex) { throw new BizException(ResultCode.CONFLICT, "用户名已存在"); } } @@ -155,7 +154,7 @@ public class UserServiceImpl extends ServiceImpl impleme entity.setStatus(UserStatusEnum.NORMAL); try { save(entity); - } catch (DuplicateKeyException | DataIntegrityViolationException ex) { + } catch (DataIntegrityViolationException ex) { throw new BizException(ResultCode.CONFLICT, "导入失败,用户名已存在: " + row.getUsername()); } }