사용자인지 유저인지 역할을 주어지게 하려고 Enum 클래스를 사용했다. 문자열 "USER"로 저장되는 것을 의도했지만 0 또는 1로 저장되는 일이 발생했다.
Entity에서 수정해야한다.
package com.example.pcmoa.user.entity;
import com.example.pcmoa.config.entity.BaseEntity;
import com.example.pcmoa.user.entity.dto.UserSignUpDto;
import com.example.pcmoa.user.entity.repository.UserRole;
import groovyjarjarantlr4.v4.runtime.misc.NotNull;
import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
@Entity
@Getter
@NoArgsConstructor
@Table(name = "pcmoa_users")
public class Users extends BaseEntity {
@Column(unique = true)
private String email;
@Column
@NotNull
private String password;
@Column
@NotNull
private String passwordCheck;
@Column
@NotNull
private String name;
@Column
@NotNull
private String phoneNumber;
@Column
@NotNull
private String birthday;
@Column
@NotNull
private String sex;
@NotNull
private boolean isAgree;
@Column
@NotNull
private UserRole userRole;
@Builder
public Users(String email, String password, String passwordCheck, String name, String phoneNumber, String birthday,
String sex, boolean isAgree, UserRole userRole) {
this.email = email;
this.password = password;
this.passwordCheck = passwordCheck;
this.name = name;
this.phoneNumber = phoneNumber;
this.birthday = birthday;
this.sex = sex;
this.isAgree = isAgree;
this.userRole = userRole;
}
public static Users toEntity(UserSignUpDto userSignUpDto, UserRole userRole, PasswordEncoder passwordEncoder) {
return Users.builder()
.email(userSignUpDto.getEmail())
.password(passwordEncoder.encode(userSignUpDto.getPassword()))
.passwordCheck(passwordEncoder.encode(userSignUpDto.getPasswordCheck()))
.name(userSignUpDto.getName())
.phoneNumber(userSignUpDto.getPhoneNumber())
.birthday(userSignUpDto.getBirthday())
.sex(userSignUpDto.getSex())
.isAgree(userSignUpDto.isAgree())
.userRole(userRole)
.build();
}
}
기존에 코드를 이렇게 사용하고 있었다. UserRole 부분에 @Enumerated(value = EnumType.STRING)를 추가하고 해결할 수 있었다.
'personal project > 에러 해결' 카테고리의 다른 글
403 에러, 스택 오버플로우, ... (0) | 2024.03.03 |
---|---|
css 적용과 불러오지 못할 경우 (0) | 2024.03.03 |
데이터베이스 charset 값으로 인한 문제 (0) | 2024.03.03 |
CI/CD로 AWS 배포를 구축하면서 발생한 것들 (0) | 2024.02.28 |
spring initializr 설치 이후 생기는 문제 (0) | 2024.02.27 |