#3 DB 연결

안떽왕·2023년 10월 15일
0

seamless 프로젝트

목록 보기
3/5

저는 mysql을 사용했고 데이터베이스 툴로 DBeaver를 사용했습니다.

DB생성

seamless라는 데이터베이스를 생성하고 users 테이블을 만들어 UserEntity에서 작성했던 대로 필드를 작성했습니다.

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String email;
    private String password;
    private String nickname;
    private String gender;
    private int age;
    private LocalDate birthdate;
    private LocalDateTime created_at;
    private LocalDateTime updated_at;
    private int access;

id필드는 PK(primary key)로 등록해주고 Not NullAuto Increment 옵션을 사용해 null값이 들어오지 못하고 새로운 데이터가 들어올때마다 1씩 증가하게 설정했습니다.

email, password, gender, age 필드를 not null로 두어 반드시 데이터가 들어오게끔 설정해줬습니다.

email, password는 회원가입에 기본이 되는 내용이기에 not null을 두었는데 추후 소셜로그인을 사용해게되면 password필드는 not null을 풀어줄 생각입니다.

gender, age는 심리상담을 위해 반드시 필요한 내용이라고 들었기에 우선 null이 들어오지 못하게 하고, 추후 소셜로그인을 사용해 얻게 될 나이, 연령대, 생년월일 등 들어오는 데이터에 따라 로직을 수정하고 필드를 수정하여 확실히 잡아 나가겠습니다.

bulid.gradle 파일에 의존성확인

dependencies {
	runtimeOnly 'com.mysql:mysql-connector-j'
}

application.properties에 DB 정보 추가

#DB URL
spring.datasource.url=jdbc:mysql://localhost:<포트번호>/<DB이름>?useSSL=false&serverTimezone=UTC

# 계정 이름
spring.datasource.username=<계정명>

# 비밀번호
spring.datasource.password=<비밀번호>

# MYSQL 설정 
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

예시

spring.datasource.url=jdbc:mysql://localhost:3306/seamless?useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456789
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
profile
이제 막 개발 배우는 코린이

0개의 댓글