V
V
Vladimir2021-06-22 20:20:46
Java
Vladimir, 2021-06-22 20:20:46

How to set time format in CreatedDate annotation in Spring?

I have this entity:

@Data
@EntityListeners(value = AuditingEntityListener.class)
public abstract class BaseEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(nullable = false, updatable = false)
    private Long id;
    @Column(updatable = false)
    @CreatedDate
    @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss")
    private LocalDateTime createdDate;
}


And this JpaAuditing config:
@Configuration
@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
public class EntityListenerConfig {
    @Bean
    public AuditorAware<String> auditorProvider() {
        return () -> Optional.ofNullable("system");
    }
}


A time record of this type is created in the database: How can I configure it to keep the normal date format, as specified in @JsonFormat ? For some reason it doesn't work
"createdDate": "2021-06-22T19:42:37.805621"

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question