@Entity
User클래스가 알아서 자동으로 mysql에 테이블이 생성된다
@Id
primaryKey
@GeneratedValue(strategy = GenerationType.IDENTITY)
yaml->use-new-id-generator-mappings: false
jpa의 넘버링X
오라클이면 시퀀스 mysql increment
@Column
칼럼 @Column(nullable= false, length = 30 , unique=true)
@CreationTimestamp
시간 자동으로 입력
@Enumerated(EnumType.STRING)
Enum 타입이 없기 때문에 DB에 알려준다!
*yaml _JPA
jpa:
open-in-view: true
hibernate:
ddl-auto: create// ----------- 새로운 table을 생성해줍니다
naming:
physical-strategy:org.hibernate.boot.model.naming.
//PhysicalNamingStrategyStandardImpl
//private int id; 그대로 table을 생성 해주겠다
//SpringPhysiaNamingStrategy를 쓰게 되면
//필드명 myEmail -> 칼럼명이 my_email 로 저장 되게 됩니다.
use-new-id-generator-mappings: false //jpa의 넘버링 전략을 따라가자 읺는다
show-sql: true //console 창에 나타냅니다
properties:
hibernate.format_sql: true //console창에 잘 정리해서 보여준다
Model _User.java
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)/
private int id;
@Column(nullable= false, length = 30 , unique=true)
private String username;
@Column(nullable= false, length = 30)
private String password;
@Column(nullable= false, length = 30)
private String email;
//DB에는 RoleType 이라는게 없다.
@Enumerated(EnumType.STRING)
private RoleType role; // 매니저 , 유저 타입을 2개
@CreationTimestamp
private Timestamp createDate;
}
enum RoleType
package com.cos.blog.model;
public enum RoleType {
USER,ADMIN
}