spring boot 二 集成 FastJson
来源:互联网 发布:js刷新父页面的frame 编辑:程序博客网 时间:2024/05/16 10:33
1、在 pom.xml 导包 (必须高于 1.2.10 版本)
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.15</version> </dependency>
2、在 Spring boot 启动类配置 Json解析。(配置方法有两种)
第一种 (继承 WebMvcConfigurerAdapter 重写 configureMessageConverters方法 添加 FastJson 到 converters中)
@SpringBootApplicationpublic class App extends WebMvcConfigurerAdapter{ @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { super.configureMessageConverters(converters); //创建 FastJson FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastConfig = new FastJsonConfig(); //配置 FastJson 基本设置 fastConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); fastConverter.setFastJsonConfig(fastConfig); //配置 FastJson 到 Spring boot中。 converters.add(fastConverter); } public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); }}
方法二 @Bean 注入方式:(简单,直接注入 FastJson 到 HttpMessageConverters 中)
@SpringBootApplicationpublic class App{ @Bean public HttpMessageConverters fastJsonHttpMessageConverter(){ FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastConfig = new FastJsonConfig(); fastConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); fastConverter.setFastJsonConfig(fastConfig); return new HttpMessageConverters((HttpMessageConverter)fastConverter); } public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); }}
阅读全文
0 0
- spring boot 二 集成 FastJson
- Spring Boot <二> fastJSON的使用
- spring boot集成mysql(二)
- spring boot & mybatis 集成二
- spring boot 配置fastjson
- spring boot 使用fastjson
- spring boot使用fastjson
- spring boot + fastjson
- spring boot 自学笔记(二) 集成Mybatis
- Spring Boot (二)集成Mybatis、Druid
- [spring-boot] 集成shiro (二)
- (二)spring-boot集成Redis(初级)
- spring boot杂记fastjson swagger
- spring boot 整合 resteasy+fastjson
- Spring boot引入引入fastjson
- Spring Boot 集成MyBatis
- Spring Boot 集成Swagger
- Spring Boot 集成Mybatis
- Exception in thread "main" org.hibernate.HibernateException: Access to DialectResolutionInfo cannot
- table固定头部,表格tbody可上下左右滑动
- Edittext做图文混排编辑
- 一个经典的PHP文件上传类分享
- Dagger+MVP+Retrofit+Rxjava+Rxlifecycle Demo
- spring boot 二 集成 FastJson
- ConstraintLayout
- Mongodb亿级数据量的性能测试
- tensorflow下有关图片的随机翻转、随机调整亮度以及对比度函数
- Python开发者2017应该关注的7个类库
- 【机器学习】最大熵模型推导
- 是
- 数据结构
- 打造前端 Deepin Linux 工作环境——安装 nodejs 环境,git 版本管理