更新 docs/tasks/任务6-Sprint-1-注册接口实现.md
This commit is contained in:
parent
23587d11fb
commit
dc86b69fd4
@ -212,7 +212,10 @@ public class AuthService {
|
|||||||
*/
|
*/
|
||||||
public User register(RegisterRequest reg) {
|
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();
|
User user = new User();
|
||||||
// 设置密码,暂时使用明文密码
|
// 设置密码,暂时使用明文密码
|
||||||
|
Loading…
Reference in New Issue
Block a user