|
@@ -1,8 +1,12 @@
|
|
package com.fd.config;
|
|
package com.fd.config;
|
|
|
|
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
|
+import com.alibaba.fastjson.serializer.ToStringSerializer;
|
|
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
|
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
|
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
|
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
+import com.fasterxml.jackson.databind.module.SimpleModule;
|
|
|
|
+import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
|
|
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
|
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
@@ -36,7 +40,7 @@ public class WebMvcConfg implements WebMvcConfigurer {
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
registry.addInterceptor(myInterceptor())
|
|
registry.addInterceptor(myInterceptor())
|
|
// .addPathPatterns("/**")
|
|
// .addPathPatterns("/**")
|
|
- .addPathPatterns("/api/cesium/**")
|
|
|
|
|
|
+ .addPathPatterns("/api/**")
|
|
.excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html");
|
|
.excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -55,6 +59,7 @@ public class WebMvcConfg implements WebMvcConfigurer {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* fastJson相关设置
|
|
* fastJson相关设置
|
|
* Dto包含json,需要配置不然会异常
|
|
* Dto包含json,需要配置不然会异常
|
|
@@ -62,15 +67,46 @@ public class WebMvcConfg implements WebMvcConfigurer {
|
|
*/
|
|
*/
|
|
@Bean
|
|
@Bean
|
|
public HttpMessageConverters customConverters() {
|
|
public HttpMessageConverters customConverters() {
|
|
- FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
|
|
|
- fastJsonConfig.setSerializerFeatures(SerializerFeature.QuoteFieldNames, SerializerFeature.WriteDateUseDateFormat, SerializerFeature.WriteNonStringValueAsString);
|
|
|
|
|
|
+
|
|
|
|
|
|
FastJsonHttpMessageConverter fastJson = new FastJsonHttpMessageConverter();
|
|
FastJsonHttpMessageConverter fastJson = new FastJsonHttpMessageConverter();
|
|
|
|
+
|
|
|
|
+ // 创建FastJson信息转换对象
|
|
|
|
+ FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建FastJsonConfig对象并设定序列化规则 序列化规则详见SerializerFeature类中
|
|
|
|
+ *
|
|
|
|
+ * 加入 fastJsonConfig.setSerializerFeatures 这方法,swagger会受影响。
|
|
|
|
+ * 目前把他注释掉,也能正常访问发送强求,先用着
|
|
|
|
+ * fastJsonConfig.setSerializerFeatures(SerializerFeature.QuoteFieldNames, SerializerFeature.WriteDateUseDateFormat, SerializerFeature.WriteNonStringValueAsString);
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ // 设置全程返回时间
|
|
|
|
+ fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ // 设置返回值为null是时输出,不写的话,null 字段 不返回。也可以设置返回空串
|
|
|
|
+ fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue);
|
|
fastJson.setFastJsonConfig(fastJsonConfig);
|
|
fastJson.setFastJsonConfig(fastJsonConfig);
|
|
|
|
+
|
|
|
|
+ //3、中文乱码解决方案
|
|
List<MediaType> mediaTypeList = new ArrayList<>();
|
|
List<MediaType> mediaTypeList = new ArrayList<>();
|
|
- mediaTypeList.add(MediaType.valueOf("application/json;charset=UTF-8"));
|
|
|
|
|
|
+ mediaTypeList.add(MediaType.APPLICATION_JSON_UTF8);
|
|
mediaTypeList.add(MediaType.valueOf("text/html;charset=UTF-8"));
|
|
mediaTypeList.add(MediaType.valueOf("text/html;charset=UTF-8"));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //4、将转换规则应用于转换对象
|
|
fastJson.setSupportedMediaTypes(mediaTypeList);
|
|
fastJson.setSupportedMediaTypes(mediaTypeList);
|
|
|
|
+
|
|
|
|
+
|
|
return new HttpMessageConverters(fastJson);
|
|
return new HttpMessageConverters(fastJson);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|