|
@@ -1,11 +1,20 @@
|
|
|
package com.gis.common.config;
|
|
|
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
+import com.alibaba.fastjson.support.config.FastJsonConfig;
|
|
|
+import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* Created by owen on 2020/2/18 0018 12:01
|
|
|
*/
|
|
@@ -35,4 +44,37 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
|
registry.addInterceptor(commonInterceptor).addPathPatterns("/**");
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * fastJson相关设置
|
|
|
+ * Dto包含json,需要配置不然会异常
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Bean
|
|
|
+ public HttpMessageConverters customConverters() {
|
|
|
+
|
|
|
+ FastJsonHttpMessageConverter fastJson = new FastJsonHttpMessageConverter();
|
|
|
+ // 创建FastJson信息转换对象
|
|
|
+ FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
|
|
+
|
|
|
+
|
|
|
+ // 设置全程返回时间
|
|
|
+ fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ // 设置返回值为null是时输出,不写的话,null 字段 不返回。也可以设置返回空串, 可以同时设置多个
|
|
|
+ fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullStringAsEmpty);
|
|
|
+
|
|
|
+ fastJson.setFastJsonConfig(fastJsonConfig);
|
|
|
+
|
|
|
+ //3、中文乱码解决方案
|
|
|
+ List<MediaType> mediaTypeList = new ArrayList<>();
|
|
|
+ mediaTypeList.add(MediaType.APPLICATION_JSON_UTF8);
|
|
|
+ mediaTypeList.add(MediaType.valueOf("text/html;charset=UTF-8"));
|
|
|
+
|
|
|
+ //4、将转换规则应用于转换对象
|
|
|
+ fastJson.setSupportedMediaTypes(mediaTypeList);
|
|
|
+
|
|
|
+ return new HttpMessageConverters(fastJson);
|
|
|
+ }
|
|
|
+
|
|
|
}
|