createAt, modifiedAt 세팅

terranking·2024년 1월 18일
0

Spring

목록 보기
6/7
post-thumbnail

springboot 3.2.1

BaseTimeEntity

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseTimeEntity {

    @Column(nullable = false)
    @CreatedDate
    private String createdAt;

    @Column(nullable = false)
    @LastModifiedDate
    private String modifiedAt;

    @PrePersist
    public void onPrePersist() {
        this.createdAt = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        this.modifiedAt = createdAt;
    }

    @PreUpdate
    public void onPreUpdate() {
        this.modifiedAt = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
}

Application

@EnableJpaAuditin 추가
profile
back-end newbie🌱

0개의 댓글