|
@@ -1,35 +1,52 @@
|
|
|
-package com.platform.yijia.config;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
-import com.alibaba.fastjson.support.config.FastJsonConfig;
|
|
|
-import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
|
|
-import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
-import org.springframework.http.converter.HttpMessageConverter;
|
|
|
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
-
|
|
|
-/**
|
|
|
- * 添加与WebMvc相关的自定义配置
|
|
|
- * @since 2020-06-11
|
|
|
- */
|
|
|
-@Configuration
|
|
|
-public class WebMvcConfig implements WebMvcConfigurer {
|
|
|
- /**
|
|
|
- * 将FastJsonHttpMessageConverter包装成HttpMessageConverter对象,并用其参与消息转换器管道
|
|
|
- * 列表HttpMessageConverters的初始化和Bean的生成,该方式会将得到的HttpMessageConverters中
|
|
|
- * 的httpMessageConverter作为生成消息转换器管道列表的初始数据(从源码得知会早于默认转换器),
|
|
|
- * 因此也会早于通过实现configureMessageConverters接口向消息转换器管道列表追加转换器的方式
|
|
|
- *
|
|
|
- * @return 最终版的Http消息转换器列表对象
|
|
|
- */
|
|
|
-// @Bean
|
|
|
-// public HttpMessageConverters fastJsonConverters() {
|
|
|
-// FastJsonHttpMessageConverter fastJsonConverter = new FastJsonHttpMessageConverter();
|
|
|
-// FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
|
|
-// fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
|
|
|
-// fastJsonConverter.setFastJsonConfig(fastJsonConfig);
|
|
|
-// HttpMessageConverter<?> httpMessageConverter = fastJsonConverter;
|
|
|
-// return new HttpMessageConverters(httpMessageConverter);
|
|
|
+//package com.platform.yijia.config;
|
|
|
+//
|
|
|
+//import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
+//import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+//import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
|
|
+//import com.fasterxml.jackson.databind.module.SimpleModule;
|
|
|
+//import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.beans.factory.annotation.Value;
|
|
|
+//import org.springframework.context.annotation.Bean;
|
|
|
+//import org.springframework.context.annotation.Configuration;
|
|
|
+//import org.springframework.http.converter.HttpMessageConverter;
|
|
|
+//import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
|
+//import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
|
|
+//
|
|
|
+//import java.text.SimpleDateFormat;
|
|
|
+//import java.util.List;
|
|
|
+//import java.util.TimeZone;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * 添加与WebMvc相关的自定义配置
|
|
|
+// */
|
|
|
+//@Configuration
|
|
|
+//public class WebMvcConfig extends WebMvcConfigurationSupport {
|
|
|
+//
|
|
|
+// @Value("${spring.jackson.date-format}")
|
|
|
+// private String dateFormatPattern;
|
|
|
+//
|
|
|
+// @Value("${spring.jackson.time-zone}")
|
|
|
+// private String timeZone;
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
|
|
+// MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
|
|
+// ObjectMapper objectMapper = converter.getObjectMapper();
|
|
|
+// // 生成JSON时,将所有Long转换成String
|
|
|
+// SimpleModule simpleModule = new SimpleModule();
|
|
|
+// simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
|
|
|
+// simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
|
|
|
+// objectMapper.registerModule(simpleModule);
|
|
|
+// // 时间格式化
|
|
|
+// objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
+// //这个可以引用spring boot yml 里的格式化配置和时区配置
|
|
|
+// objectMapper.setDateFormat(new SimpleDateFormat(dateFormatPattern));
|
|
|
+// objectMapper.setTimeZone(TimeZone.getTimeZone(timeZone));
|
|
|
+// // 设置格式化内容
|
|
|
+// converter.setObjectMapper(objectMapper);
|
|
|
+// converters.add(0, converter);
|
|
|
+// super.extendMessageConverters(converters);
|
|
|
// }
|
|
|
-}
|
|
|
+//
|
|
|
+//}
|