반응형
package site.metacoding.blogv2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
@EnableJpaAuditing // 시간을 자동으로 넣어주는 JPA 어노테이션 추가
@SpringBootApplication
public class BlogV2Application {
public static void main(String[] args) {
SpringApplication.run(BlogV2Application.class, args);
}
}
package site.metacoding.blogv2.domain.post;
import java.time.LocalDateTime;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@EntityListeners(AuditingEntityListener.class) // 추가
@Entity
public class Post { // N(드라이빙 테이블, FK의 주인)
@CreatedDate // 추가
private LocalDateTime createDate;
@LastModifiedDate // 추가
private LocalDateTime updateDate;
}
[출처]
https://cafe.naver.com/metacoding
메타 코딩 유튜브
https://www.youtube.com/c/%EB%A9%94%ED%83%80%EC%BD%94%EB%94%A9
반응형