JPA新增entity時自動填充時間,例建立時間,修改時間

背景:springboot項目,集成JPA,與數據庫交互的entity,與用戶交互的DTO前端

問題:添加酒店時,兩個字段create_time,update_time,前端不傳數據,若是賦值spring

解決:數據庫

1. 在啓動類上添加@EnableJpaAuditing,啓動springboot

2. 在實體類添加@EntityListeners(AuditingEntityListener.class)it

3.在字段上添加@CreatedDate,@LastModifiedDateast

相關文章
相關標籤/搜索