//만약 (name = "member")생략되면 테이블의 이름은 MemberEntity가 된다.
@Table(name = "member")
public class MemberEntity extends BaseTime {...}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int mno;
//아이디 Column
@Column(nullable = false) // null값 허용X
private String memail;
//비밀번호 Column
@Column
private String mpassword;
//이름 Column
@Column
private String mname;
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class) //AppStart의 @EnableJpaAuditing와 세트
public class BaseTime {
@CreatedDate
public LocalDateTime cdate; //생성날짜/시간 [호출하기 위해 public]
@LastModifiedDate
public LocalDateTime udate; //수정날짜/시간 [호출하기 위해 public]
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity
@Table(name = "member")
// BaseTime을 상속받는 MemberEntity
public class MemberEntity extends BaseTime {...}
JPA Auditing
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class) //AppStart의 @EnableJpaAuditing와 세트
public class BaseTime {
@CreatedDate
public LocalDateTime cdate; //생성날짜/시간 [호출하기 위해 public]
@LastModifiedDate
public LocalDateTime udate; //수정날짜/시간 [호출하기 위해 public]
}
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
@SpringBootApplication // 하위 폴더내 컴포넌트 스캔 빈 등록
@EnableJpaAuditing //BaseTime의 @EntityListeners(AuditingEntityListener.class)와 세트
public class AppStart {
public static void main(String[] args) {
SpringApplication.run(AppStart.class);
}
}