如何将查出的日期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));
     }

posted @ 2017-06-29 11:49  路途寻码人  阅读(1583)  评论(0编辑  收藏  举报