码迷,mamicode.com
首页 > 编程语言 > 详细

springboot配置springMVC

时间:2019-11-19 17:13:16      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:frame   ide   mes   mvcc   sage   over   sed   simple   bean   

/**
 * @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

标签:frame   ide   mes   mvcc   sage   over   sed   simple   bean   

原文地址:https://www.cnblogs.com/jagng951014/p/11890530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!