|
|
@@ -15,19 +15,34 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
+import org.springframework.http.converter.HttpMessageConverter;
|
|
|
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
|
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.List;
|
|
|
|
|
|
@Configuration
|
|
|
-public class JacksonConfig {
|
|
|
+public class JacksonConfig implements WebMvcConfigurer {
|
|
|
|
|
|
private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
|
|
private static final String DATE_FORMAT = "yyyy-MM-dd";
|
|
|
private static final String TIME_FORMAT = "HH:mm:ss";
|
|
|
|
|
|
+ /**
|
|
|
+ * 关键:通过 WebMvcConfigurer 直接配置消息转换器
|
|
|
+ * 确保自定义 ObjectMapper 被 Spring MVC 的 HTTP 响应序列化使用
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
|
+ MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
|
|
+ converter.setObjectMapper(objectMapper());
|
|
|
+ converters.add(0, converter); // 添加到最前面,优先使用
|
|
|
+ }
|
|
|
+
|
|
|
@Bean
|
|
|
@Primary
|
|
|
public ObjectMapper objectMapper() {
|