配置一个Bean就行了

private static final String DATE_TIME_FMT = "yyyy-MM-dd HH:mm:ss";


/** * * LocalDateTime日期转换两个问题: * 1.前端传入参数时String转换为Date。 * 2.后台返回值时Date转换为String * @return */ @Bean public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() { JavaTimeModule module = new JavaTimeModule(); module.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DATE_TIME_FMT))); module.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DATE_TIME_FMT))); return builder -> { builder.simpleDateFormat(DATE_TIME_FMT); builder.deserializers(new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DATE_TIME_FMT))); builder.serializers(new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DATE_TIME_FMT))); builder.modules(module); }; }