1、引入fastJson插件

<!-- 引入fastjson插件 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.32</version>
</dependency> <!-- 打包插件 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork><!-- 热部署生效必须加 -->
</configuration>
</plugin>
</plugins>
</build>

2、两种方法实现

  2.1、在App.java文件中实现HttpMessageConverters类

  @Bean
public HttpMessageConverters fastJsonConverters(){
FastJsonHttpMessageConverter fastJsonConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastConf = new FastJsonConfig(); fastConf.setSerializerFeatures(SerializerFeature.PrettyFormat);
fastJsonConverter.setFastJsonConfig(fastConf); HttpMessageConverter<?> converter = fastJsonConverter;
return new HttpMessageConverters(converter);
}

  2.2、在App.java类继承WebMvcConfigurerAdapter类,并重写configureMessageConverters方法

@SpringBootApplication
public class App extends WebMvcConfigurerAdapter{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
SpringApplication.run(App.class, args);
} @Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
// TODO Auto-generated method stub
super.configureMessageConverters(converters); FastJsonHttpMessageConverter fastJsonConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastConf = new FastJsonConfig(); fastConf.setSerializerFeatures(SerializerFeature.PrettyFormat);
fastJsonConverter.setFastJsonConfig(fastConf); converters.add(fastJsonConverter);
} /*@Bean
public HttpMessageConverters fastJsonConverters(){
FastJsonHttpMessageConverter fastJsonConverter = new FastJsonHttpMessageConverter();
FastJsonConfig fastConf = new FastJsonConfig(); fastConf.setSerializerFeatures(SerializerFeature.PrettyFormat);
fastJsonConverter.setFastJsonConfig(fastConf); HttpMessageConverter<?> converter = fastJsonConverter;
return new HttpMessageConverters(converter);
}*/ }

3、格式化属性的值

    private String userId;
private String userName; @JSONField(format="yyyy-MM-dd")
private Date createDate;

4、测试

  格式化之前

  

  格式化之后

  

Spring Boot入门——json数据处理的更多相关文章

  1. spring boot 入门操作(二)

    spring boot入门操作 使用FastJson解析json数据 pom dependencies里添加fastjson依赖 <dependency> <groupId>c ...

  2. Spring Boot入门(五):使用JDBC访问MySql数据库

    本系列博客记录自己学习Spring Boot的历程,如帮助到你,不胜荣幸,如有错误,欢迎指正! 在程序开发的过程中,操作数据库是必不可少的部分,前面几篇博客中,也一直未涉及到数据库的操作,本篇博客 就 ...

  3. Spring Boot 入门(六):集成 treetable 和 zTree 实现树形图

    本篇文章是接着Spring Boot 入门(五):集成 AOP 进行日志管理写的,主要集成了树形图,在部门列表或者权限列表中,树形图经常被用上.主要是根据相应的 API 凭借 html 字符串 1.t ...

  4. Spring boot入门(三):SpringBoot集成结合AdminLTE(Freemarker),利用generate自动生成代码,利用DataTable和PageHelper进行分页显示

    关于SpringBoot和PageHelper,前篇博客已经介绍过Spring boot入门(二):Spring boot集成MySql,Mybatis和PageHelper插件,前篇博客大致讲述了S ...

  5. Spring Boot入门 and Spring Boot与ActiveMQ整合

    1.Spring Boot入门 1.1什么是Spring Boot Spring 诞生时是 Java 企业版(Java Enterprise Edition,JEE,也称 J2EE)的轻量级代替品.无 ...

  6. spring boot 入门(一)

    转自构建微服务:Spring boot 入门篇 什么是spring boot Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程. ...

  7. Spring boot学习1 构建微服务:Spring boot 入门篇

    Spring boot学习1 构建微服务:Spring boot 入门篇 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框 ...

  8. Spring Boot 入门之 Web 篇(二)

    原文地址:Spring Boot 入门之 Web 篇(二) 博客地址:http://www.extlight.com 一.前言 上一篇<Spring Boot 入门之基础篇(一)>介绍了 ...

  9. Spring Boot 入门 - 目录

    pring Boot 入门 - 进阶篇(3)- 定时任务(@Scheduled) 主要用于定时发送邮件.夜间自动维护等. (1)开启定时任务功能 @Configuration @EnableSched ...

随机推荐

  1. Spring基础知识详解

    Spring 概述 1. 什么是spring? Spring 是个java企业级应用的开源开发框架.Spring主要用来开发Java应用,但是有些扩展是针对构建J2EE平台的web应用.Spring ...

  2. grafana-----Time Range Controls

    Grafana提供了许多方法来管理时间的可视化数据的范围,在Dashboard-level和Panel-level都有. 在右上角,您有主仪表板时间选择器(它位于“Zoom out”和“Refresh ...

  3. Adjacency List

    w Python Patterns - Implementing Graphs | Python.orghttps://www.python.org/doc/essays/graphs/ Graph ...

  4. python系列八:Python3条件控制&循环语句

    #!/usr/bin/python #-*-coding:gbk-*-#Python3 条件控制&循环语句import randomage = int(input("请输入你的年龄: ...

  5. JQuery UI 入门

    1. JQuery UI 概述 1.1 JQuery UI 主要分为三部分: 交互部件(interactions):是一些与鼠标交互相关的内容; 小部件(widgets): 主要是一些页面的扩展; 效 ...

  6. MySQL 第六天

    回顾   外键: 关联关系(表与表之间: 表中字段指向另外一张表的主键) 外键条件: 字段类型必须一致, 存储引擎必须为innodb 外键约束: 子表约束: 不能插入父表不存在的记录 父表约束: 三种 ...

  7. adobe flash player升级coredump分析

    flash player版本号:14.0.0.125 产品名称:Adobe® Flash® Player Installer/Uninstaller 系统:windows xp sp3 调试器:win ...

  8. 理解java注解

    @是java注解,即annotation. 注解功能可以理解为插件,是代码级别的插件,在类的方法上写:@XXX,就是在代码上插入了一个插件. Java注解是附加在代码中的一些元信息,用于一些工具在编译 ...

  9. MyEclipse工具栏的隐藏与显示及自定义

    Myeclipse的工具栏 1.隐藏 工具栏---->右键---->hide toolbar 2.显示     window ----> show toolbar 3.自定义     ...

  10. 极速Node.js:来自LinkedIn的10个性能提升秘籍

    from:http://faylai.iteye.com/blog/1293194 1.避免使用同步的方法 nodejs 是基于单线程.为了让单线程能够处理高并发的请求,我们尽量要避免让线程等待,阻塞 ...