/**
* @ClassName MvcConfigure
* @Description SpringMVC配置
* @Author JAGNG
* @Date 2019/10/28 10:23
**/
@Configuration
public class MvcConfigure implements WebMvcConfigurer { /**
* @Description 返回值序列化配置
* @Param [converters]
* @Return void
* @Author JAGNG
* @Date 10:34 2019/10/28
**/
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
SimpleModule simpleModule = new SimpleModule();
//将long类型转为字符串
simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
simpleModule.addSerializer(Long.TYPE,ToStringSerializer.instance);
objectMapper.registerModule(simpleModule);
jackson2HttpMessageConverter.setObjectMapper(objectMapper);
converters.add(jackson2HttpMessageConverter);
} /**
* @Description 跨域配置
* @Return org.springframework.web.filter.CorsFilter
* @Author JAGNG
* @Date 10:33 2019/10/28
**/
@Bean
public CorsFilter corsFilter(){
UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedMethod("*");
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.setAllowCredentials(true);
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**",corsConfiguration);
return new CorsFilter(urlBasedCorsConfigurationSource);
}

  

springboot配置springMVC的更多相关文章

  1. springboot 配置springmvc?

    package com.aaa.zxf.config; import org.springframework.boot.SpringBootConfiguration; import org.spri ...

  2. java框架之SpringBoot(5)-SpringMVC的自动配置

    本篇文章内容详细可参考官方文档第 29 节. SpringMVC介绍 SpringBoot 非常适合 Web 应用程序开发.可以使用嵌入式 Tomcat,Jetty,Undertow 或 Netty ...

  3. 【SpringBoot】SpringBoot与SpringMVC自动配置(五)

    本文介绍SpringBoot对Spring MVC自动配置,SpringBoot自动配置原理可以参考:[SpringBoot]SpringBoot配置与单元测试(二) 首先新建一个SpringBoot ...

  4. springboot上传文件 & 不配置虚拟路径访问服务器图片 & springboot配置日期的格式化方式 & Springboot配置日期转换器

    1.    Springboot上传文件 springboot的文件上传不用配置拦截器,其上传方法与SpringMVC一样 @RequestMapping("/uploadPicture&q ...

  5. SpringBoot配置(1) 配置文件application&yml

    SpringBoot配置(1) 配置文件application&yml 一.配置文件 1.1 配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的. application ...

  6. SpringBoot对比SpringMVC,SpringMVC 处理请求过程

    (问较多:1.SpringBoot对比SpringMVC.2.SpringMVC 处理请求过程.问:springboot的理解 Spring,Spring MVC,Spring Boot 三者比较 S ...

  7. SpringBoot接管SpringMvc

    SpringBoot接管SpringMvc Spring Web MVC framework(通常简称为“Spring MVC”)是一个丰富的“model 视图控制器”web framework. S ...

  8. SpringBoot 源码解析 (七)----- Spring Boot的核心能力 - 自定义Servlet、Filter、Listener是如何注册到Tomcat容器中的?(SpringBoot实现SpringMvc的原理)

    上一篇我们讲了SpringBoot中Tomcat的启动过程,本篇我们接着讲在SpringBoot中如何向Tomcat中添加Servlet.Filter.Listener 自定义Servlet.Filt ...

  9. 003 SpringBoot整合SpringMVC、Mybatis 案例

    1.不使用骨架创建一个maven工程 2.修改POM.xml文件 <?xml version="1.0" encoding="UTF-8"?> &l ...

随机推荐

  1. 公共DNS性能大比拼

    ​ 今天中午,访问Gitee突然访问不进去,然后收到红薯通知:阿里云停止了 Gitee.com 的域名解析. ​ ​ 码云官方也随后给出解决办法 没有任何提示,没有任何提前通知,阿里云停止了 Gite ...

  2. EF通过导航属性取出从表的集合后,无法删除子表

    主从表是配了级联删除的,如果通过导航属性去除从表明细删除时将报错The relationship could not be changed because one or more of the for ...

  3. Java学习笔记之面向对象

    面向对象概念 面向对象编程 &面向过程编程 面向对象:关心是谁来做 面向过程:关心的是怎么做 面向对象总结成一句话:就是分工与协作,干活的是对象 生活中: 对象 -----抽象-------- ...

  4. PHP array_reduce

    1.函数的作用:用函数迭代数组的所有元素 2.函数的参数: @params  array  $array   用于迭代的数组 @params  callable  $callback  迭代的函数 @ ...

  5. eclipse中最有用的10个快捷键

    这里列出一些在使用eclipse的过程中最有用的10个快捷键,通过灵活使用这些快捷键可以提高开发效率和开发质量. 1. [ctrl+shift+r]打开资源 这可能是所有快捷键中最省时间的了.这个快捷 ...

  6. opencv::调整图像亮度与对比度

    图像变换可以看作如下: - 像素变换 – 点操作 - 邻域操作 – 区域 调整图像亮度和对比度属于像素变换-点操作 //创建一张跟原图像大小和类型一致的空白图像.像素值初始化为0 Mat new_im ...

  7. Java线程池构造参数详解

    在ThreadPoolExecutor类中有4个构造函数,最终调用的是如下函数: public ThreadPoolExecutor(int corePoolSize, int maximumPool ...

  8. UltraEdit等软件详细安装破解教程,附注册机(全网独家可用)

    --- title: "UltraEdit等软件详细安装破解教程,附注册机(全网独家可用)" categories: soft tags: soft author: LIUREN ...

  9. 使用eclipse在tomcat中设置项目启动的虚拟路径

    很多时候我们在启动项目的时候都会在浏览器输入"localhost:+端口号+项目名称" 其实tomcat是可以省去这种麻烦的,通过设置项目的虚拟路径就可访问项目了 第一步 选择ec ...

  10. Leetcode刷题记录(python3)

    Leetcode刷题记录(python3) 顺序刷题 1~5 ---1.两数之和 ---2.两数相加 ---3. 无重复字符的最长子串 ---4.寻找两个有序数组的中位数 ---5.最长回文子串 6- ...