controller:

@ResponseBody
@RequestMapping("/date")
public Person date(Person p) {
System.out.println(p.toString());
return new Person("张三",15,new Date());
}

在person类的日期类型属性get方法配置:

@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
public Date getBirthday() {
return birthday;
}

控制台输出:

Person [name=好兄弟, age=337, birthday=Tue Oct 03 12:12:12 CST 1995]

前端返回结果:

{"name":"张三","age":15,"birthday":"2017-09-27"}

参考自:charley251的文章  spring mvc4使用及json 日期转换解决方案

地址:http://blog.csdn.net/zhanngle/article/details/24123659/

 

相关文章:

  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 1970-01-01
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-25
  • 2022-02-08
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2022-02-08
相关资源
相似解决方案