WebMvcConfigurationSupport跨域和fastjson全局替换
发布时间:2020-12-16 18:40:04 所属栏目:百科 来源:网络整理
导读:@Configurationpublic class WarnWebMvcConfigurationSupport extends WebMvcConfigurationSupport { /** * @Author AlanMa * @Description 全局fastJson替换 * @Param [converters] * @return void */ @Override public void configureMessageConverters(Li
@Configuration public class WarnWebMvcConfigurationSupport extends WebMvcConfigurationSupport { /** * @Author AlanMa * @Description 全局fastJson替换 * @Param [converters] * @return void */ @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { super.configureMessageConverters(converters); FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures( SerializerFeature.PrettyFormat,SerializerFeature.WriteNullListAsEmpty,SerializerFeature.WriteMapNullValue,SerializerFeature.WriteEnumUsingToString,SerializerFeature.WriteNullStringAsEmpty); fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss"); List<MediaType> fastMediaTypes = new ArrayList<>(); fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8); fastConverter.setSupportedMediaTypes(fastMediaTypes); fastConverter.setFastJsonConfig(fastJsonConfig); converters.add(fastConverter); } @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins("*") .allowedMethods("POST","GET","PUT","OPTIONS","DELETE") .maxAge(3600) .allowCredentials(true); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |