|
@@ -1,87 +1,89 @@
|
|
|
-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 com.gis.common.constant.ConfigConstant;
|
|
|
-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
|
|
|
- */
|
|
|
-@Configuration
|
|
|
-public class WebMvcConfig implements WebMvcConfigurer {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommonInterceptor commonInterceptor;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ConfigConstant configConstant;
|
|
|
-
|
|
|
- /**
|
|
|
- * 配置全局跨域
|
|
|
- * 开发、测试环境开启跨域, 正式环境不开启
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void addCorsMappings(CorsRegistry registry) {
|
|
|
- String active = configConstant.active;
|
|
|
- if ("dev".equals(active) || "sit".equals(active)){
|
|
|
- registry.addMapping("/**")
|
|
|
- .allowedOrigins("*")
|
|
|
- .allowCredentials(true)
|
|
|
- .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
|
|
|
- .maxAge(3600);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 添加拦截器
|
|
|
- */
|
|
|
- @Override
|
|
|
- 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");
|
|
|
- // 设置返回值为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);
|
|
|
- }
|
|
|
-}
|
|
|
+//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 com.gis.common.constant.ConfigConstant;
|
|
|
+//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
|
|
|
+// */
|
|
|
+//@Configuration
|
|
|
+//public class WebMvcConfig implements WebMvcConfigurer {
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private CommonInterceptor commonInterceptor;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// ConfigConstant configConstant;
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 配置全局跨域
|
|
|
+// * 开发、测试环境开启跨域, 正式环境不开启
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// public void addCorsMappings(CorsRegistry registry) {
|
|
|
+// String active = configConstant.active;
|
|
|
+// if ("dev".equals(active) || "sit".equals(active)){
|
|
|
+// registry.addMapping("/**")
|
|
|
+// .allowedOrigins("*")
|
|
|
+// .allowCredentials(true)
|
|
|
+// .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
|
|
|
+// .maxAge(3600);
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 添加拦截器
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// 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");
|
|
|
+// // 设置返回值为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);
|
|
|
+// }
|
|
|
+//}
|