기본로직

🍯 Tip!
import단축키: Alt+Shift+Enter
package com.example.euserservice.vo;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
@Data
public class RequestUser {
@NotNull(message = "Email cannot be null")
@Size(min = 2, message = "Email not be less than two characters")
@Email
private String email;
@NotNull(message = "Name cannot be null")
@Size(min = 2, message = "Name not be less than two characters")
private String name;
@NotNull(message = "Password cannot be null")
@Size(min = 8, message = "Password must be equal or grater than 8 characters")
private String pwd;
}
💡 참고
pom.xml에 다음과 같은 의존성 추가
@NotNull,@Size을 사용하기 위해서 의존성 주입 필요<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency>
✅ 상세 설명
입력 받을 때 데이터 조건 설정
@NotNull: 필수값 지정@Size: 데이터의 크기 지정message: 해당 설정에 올바르지 않으면 Message가 출력됨
package com.example.euserservice.dto;
import lombok.Data;
import java.util.Date;
@Data
public class UserDto {
private String email;
private String name;
private String pwd;
private String userId;
private Date createdAt;
private String encryptedPwd;
}
✅ DTO (Data Transfer Object)
순수하게 데이터를 담아 계층간 전달하는 객체
VO와 달리 로직을 포함할 수 없음
(🔗 출처: [JAVA] DTO와 VO의 차이)
package com.example.euserservice.service;
import com.example.euserservice.dto.UserDto;
public interface UserService {
UserDto createUser(UserDto userDto);
}
✅ 상세한 구현은
ServiceImpl에서 진행
package com.example.euserservice.service;
import com.example.euserservice.dto.UserDto;
import org.springframework.stereotype.Service;
import java.util.UUID;
@Service
public class UserServiceImpl implements UserService {
@Override
public UserDto createUser(UserDto userDto) {
userDto.setUserId(UUID.randomUUID().toString());
return null;
}
}
✅ 상세 설명
createUser()메서드 호출 시,userDto중userId값에
랜덤으로 UUID를 생성하여 값을 셋팅해줌.
✅ UUID란?
'Universally Unique Identifier'의 약자로 128-bit의 고유 식별자
즉, 네트워크 상에서 고유성이 보장되는 id를 만들기 위한 표준 규약
(🔗 출처: UUID(Universally Unique Identifier)란?)