WebMvcConfigurationSupport跨域和fastjson全局替换
@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);
}
}
WebMvcConfigurationSupport跨域和fastjson全局替换的更多相关文章
- spring mvc跨域设置(全局)
//--------------第一步//spring 5版本全局配置方式 @Configuration @EnableWebMvc public class SpringMvcBeans imple ...
- CORS跨域请求:前后端分离
1. 请求过滤器: /** * OncePerRequestFilter保证在任何Servlet容器中都是一个请求只执行一次的过滤器. */ public class CorsFilter exten ...
- 第五节:SignalR大杂烩(与MVC融合、全局的几个配置、跨域的应用、C/S程序充当Client和Server)
一. 说在前面的话 本节主要在前面章节的基础上补充了几个简单的知识点,比如:第三方调用通过 GlobalHost.ConnectionManager.GetHubContext<MySpecHu ...
- 使用ajax请求接口,跨域后cookie无法设置,全局配置ajax;及使用axios跨域后cookie无法设置,全局配置axios
问题一: 使用ajax/axios跨域请求接口,后端放行了,能够正常获取数据,但是cookie设置不进去,后端登录session判断失效 ajax解决办法: //设置ajax属性 crossDomai ...
- 并发编程概述 委托(delegate) 事件(event) .net core 2.0 event bus 一个简单的基于内存事件总线实现 .net core 基于NPOI 的excel导出类,支持自定义导出哪些字段 基于Ace Admin 的菜单栏实现 第五节:SignalR大杂烩(与MVC融合、全局的几个配置、跨域的应用、C/S程序充当Client和Server)
并发编程概述 前言 说实话,在我软件开发的头两年几乎不考虑并发编程,请求与响应把业务逻辑尽快完成一个星期的任务能两天完成绝不拖三天(剩下时间各种浪),根本不会考虑性能问题(能接受范围内).但随着工 ...
- 009-Spring Boot全局配置跨域请求支持
1.Spring Boot 2.0以前全局配置跨域主要是继承WebMvcConfigurerAdapter @Configuration public class CorsConfig extends ...
- gin框架中全局跨域请求处理设置
跨域访问的问题 OPTIONS请求 全局跨域访问中间件 // 跨域访问:cross origin resource share func Cors() gin.HandlerFunc { return ...
- Spring Boot2.1.3全局跨域
/** * 配置跨域访问 * * @author Terwer */ @Bean public WebMvcConfigurer corsConfigurer() { return new WebMv ...
- json替换jsonp实现跨域请求
最近遇到h5前端页面和web后端双方的请求存在跨域,普通的jquery.ajax请求已不能实现(因为js是不允许跨域的(如果可以跨域,那就能随便改别人的网页了),js的原理), 最后经过艰苦奋斗,终于 ...
随机推荐
- 事件处理机制与Handler消息传递机制
一.基于监听的事件处理机制 基于监听的时间处理机制模型: 事件监听机制中由事件源,事件,事件监听器三类对象组成 处理流程如下: Step 1:为某个事件源(组件)设置一个监听器,用于监听用户操作 St ...
- java 网络文件下载(并命中文名)
public void download(HttpServletRequest request, HttpServletResponse response){ //获取服务器文件 String fil ...
- Windows 10 共享需要网络凭据的问题
如果Windows在资源管理器的网络中双击其他的网络设备,提示要输入网络凭据的解决办法: 打开"网络共享中心" -> "更改高级共享设置"->&qu ...
- HearthBuddy BotManager
MainWindow private void button_0_Click(object sender, RoutedEventArgs e) { Configuration.Instance.Sa ...
- 清空Linux缓存
清空Linux的缓存 sync > /proc/sys/vm/drop_caches > /proc/sys/vm/drop_caches > /proc/sys/vm/drop_c ...
- rc-form 在 typescript 中的报错处理
1.创建 声明模块 index.d.ts import { Component, ClassicComponentClass, ClassType, ComponentClass, Component ...
- Spring事务注解分析
1.使用spring事务注解 2.手写事务注解 1).sql执行器 2).事务注解定义 3).AOP实现事务具体实现(同一个线程中使用同一个连接) 4).应用使用注解前 5).应用使用注解后
- LC 275. H-Index II
Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a ...
- HttpURLConnection 多线程下载
影响下载的速度 * 宽带的带宽 * 服务器的限制 * 服务器的资源固定,开启的线程越多抢占的资源就越多 import java.io.InputStream; import java.io.Rando ...
- selenium webdriver常用函数
from selenium import webdriver driver = webdriver.Ie(executable_path = "e:\\IEDriverServer" ...