zoukankan      html  css  js  c++  java
  • SpringBoot2.x整合Fastjson

    第一步:添加依赖

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.51</version>
    </dependency>

    第二步:配置

    集成 WebMvcConfigurationSupport类,并重写 configureMessageConverters(List<HttpMessageConverter<?>> converters) 方法。

    @Configuration
    public class JsonConfig extends WebMvcConfigurationSupport {
    
        @Override
        public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
            // 1、定义一个convert转换消息的对象
            FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
            // 2、添加fastjson的配置信息
            FastJsonConfig fastJsonConfig = new FastJsonConfig();
            fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
            fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
            // 3、在convert中添加配置信息
            fastConverter.setFastJsonConfig(fastJsonConfig);
            // 4、将convert添加到converters中
            converters.add(fastConverter);
            // 5、追加默认转换器
            addDefaultHttpMessageConverters(converters);
        }
    }
  • 相关阅读:
    电商工具 谷歌插件 版本 2021-03-04
    PowerDesigner 自定义脚本
    MapReduce案例之寻找共同好友
    Hadoop之MapReduce开发总结
    python之文件操作
    python字典、集合
    python元组
    python列表练习
    python之列表
    python之编码解码、字符串常用方法
  • 原文地址:https://www.cnblogs.com/Jimc/p/12511293.html
Copyright © 2011-2022 走看看