當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringBoot 使用fastjson
生活随笔
收集整理的這篇文章主要介紹了
SpringBoot 使用fastjson
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
spring boot默認使用的json解析框架是jackson,替換為fastjson有兩種方式
1.繼承WebMvcConfigurerAdapter
@SpringBootApplication public class App extends WebMvcConfigurerAdapter{@Overridepublic void configureMessageConverters(List<HttpMessageConverter<?>> converters) {super.configureMessageConverters(converters);FastJsonHttpMessageConverter fastConverter=new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig=new FastJsonConfig();fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);fastConverter.setFastJsonConfig(fastJsonConfig);converters.add(fastConverter);}public static void main(String[] args) {SpringApplication.run(App.class,args);} }2.使用@Bean注入方式
@Configuration public class WebMvcConfig{@Beanpublic HttpMessageConverters fastJsonHttpMessageConverters(){FastJsonHttpMessageConverter fastConverter=new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig=new FastJsonConfig();fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); fastConverter.setFastJsonConfig(fastJsonConfig);HttpMessageConverter<?> converter=fastConverter;return new HttpMessageConverters(converter);} }?
轉載于:https://www.cnblogs.com/april-chen/p/9012487.html
總結
以上是生活随笔為你收集整理的SpringBoot 使用fastjson的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos6创建用户,设置ssh登录
- 下一篇: 数据结构与算法 —— 二叉树