JPAでの実装時間のデフォルト設定(現在時刻をとる)
711 ワード
package com.example.springbootdemo;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import javax.persistence.*;
import java.util.Date;
@Entity
@Table(name = "test_data_time_default")
@Data
public class TestDateTimeDefault {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
//
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "t_time")
@CreationTimestamp
private Date time;
//
@Column(name = "t_update_time")
@UpdateTimestamp
@Temporal(TemporalType.TIMESTAMP)
private Date updateTime;
}