From dc86b69fd45a6f9f78aaff53d513fd26845bd798 Mon Sep 17 00:00:00 2001 From: whz <6168830@qq.com> Date: Wed, 15 May 2024 14:40:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20docs/tasks/=E4=BB=BB?= =?UTF-8?q?=E5=8A=A16-Sprint-1-=E6=B3=A8=E5=86=8C=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tasks/任务6-Sprint-1-注册接口实现.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/tasks/任务6-Sprint-1-注册接口实现.md b/docs/tasks/任务6-Sprint-1-注册接口实现.md index 6ce7999..3e7f380 100644 --- a/docs/tasks/任务6-Sprint-1-注册接口实现.md +++ b/docs/tasks/任务6-Sprint-1-注册接口实现.md @@ -212,7 +212,10 @@ 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(); // 设置密码,暂时使用明文密码