jpa 自动维护创建更新时间

2019-09-25  本文已影响0人  hk_faith
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@ToString(exclude = {"notificationUserMapList"})
@Table(name = "notification")
public class Notification {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @CreatedDate
    @Column(name = "created_at")
    private Timestamp createdAt;

    @LastModifiedDate
    @Column(name = "updated_at")
    private Timestamp updatedAt;
}

备注:

Hibernate 也提供了类似上述时间注解的功能实现,这种方法只需要一步配置,更改为注解 @UpdateTimestamp@CreationTimestamp

上一篇 下一篇

猜你喜欢

热点阅读