我正在嘗試運(yùn)行以下簡(jiǎn)單示例,但出現(xiàn)錯(cuò)誤。我正在使用@CreatedDate。但是,當(dāng)我使用Rest端點(diǎn)保存Student對(duì)象時(shí),它不會(huì)創(chuàng)建日期并拋出給定的異常。在我的休息終點(diǎn),我有 @PostMapping("/students") public Student createStudent(@Valid @RequestBody Student student){ return studentRepository.save(student); }這是我的實(shí)體...@Entity@Table(name = "students")@EntityListeners(AuditingEntityListener.class)@JsonIgnoreProperties(value = {"createdAt", "updatedAt"}, allowGetters = true)public class Student implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @NotBlank private String name; @NotBlank private String surname; @Column(nullable = false, updatable = false) @Temporal(TemporalType.TIMESTAMP) @CreatedDate private Date createdAt; @Column(nullable = false) @Temporal(TemporalType.TIMESTAMP) @LastModifiedDate private Date updatedAt;
1 回答

慕沐林林
TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊
您可能會(huì)錯(cuò)過(guò)Configuration類中的@EnableJpaAuditing批注,該批注在Spring JPA中啟用審核。
添加回答
舉報(bào)
0/150
提交
取消