diff --git a/docs/tasks/任务7-Sprint-1-基于JWT的用户认证实现.md b/docs/tasks/任务7-Sprint-1-基于JWT的用户认证实现.md index e9e6868..a22e6ce 100644 --- a/docs/tasks/任务7-Sprint-1-基于JWT的用户认证实现.md +++ b/docs/tasks/任务7-Sprint-1-基于JWT的用户认证实现.md @@ -696,7 +696,9 @@ public class AuthService { */ public User register(RegisterRequest reg) { // 检查用户名是否已存在,如果存在则抛出异常 - userRepository.findByUsername(reg.getUsername()).orElseThrow(() -> new ResourceExistedException("User","useranme="+reg.getUsername())); + userRepository.findByUsername(reg.getUsername()).ifPresent(user -> { + throw new ResourceExistedException("User","username="+reg.getUsername()); + }); // 创建用户对象并设置信息 User user = new User(); // 设置密码,暂时使用明文密码