如何将查出的日期Data类型以Json格式输出到前端

Posted 牵着妞去散步

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何将查出的日期Data类型以Json格式输出到前端相关的知识,希望对你有一定的参考价值。

方法一

  在返回的实体的属性中加上注解

 // 创建时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createDate;

方法二

  在Controller中注解一个@InitBinder,使用@ResponseBody时会将实体中的属性为Data类型的转换成JSON格式的日期

  private static final SimpleDateFormat DATEFORMAT = new SimpleDateFormat("yyyy-MM-dd");

  @InitBinder
     protected void initBinder(WebDataBinder binder) {
          binder.registerCustomEditor(Date.class, new CustomDateEditor(DATEFORMAT, true));
     }






以上是关于如何将查出的日期Data类型以Json格式输出到前端的主要内容,如果未能解决你的问题,请参考以下文章