Application 파일에 @EnableJpaAuditing 추가
package jpa.board;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
@SpringBootApplication
@EnableJpaAuditing
public class BoardApplication {
public static void main(String[] args) {
SpringApplication.run(BoardApplication.class, args);
}
}
@CreatedDate, @LastModifiedDate 선언한 entity에 위에 @EntityListeners(AuditingEntityListener.class) 선언
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@EntityListeners(AuditingEntityListener.class)
public class Board {
...
}
insert를 해보면 날짜가 들어가는것을 볼수 있습니다.