• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Failed to convert value of type ‘java.lang.String’ to required type ‘java.util.Date’

武飞扬头像
Klix
帮助1

springboot项目在接收时间类型的时候,报Failed to convert value of type ‘java.lang.String’ to required type 'java.util.Date’的错误,

这句话的意思是,把字符串转为Date类型失败了

解决方法: springboot要解决这个问题很简单,在接收的字段上面,添加下面的注解

1.前端往后端传数据

  1.  
    @DateTimeFormat(pattern=“yyyy-MM-dd HH:mm:ss”) //接收时间类型,从前端往回传的json数据被date接收,json转为data类型
  2.  
    public Date getS_time_end() {
  3.  
    return s_time_end;
  4.  
    }

2.后端往前端传数据

  1.  
    @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT 8") //时间类型转为json类型
  2.  
    public Date getS_time_end() {
  3.  
    return s_time_end;
  4.  
    }

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfkjbii
系列文章
更多 icon
同类精品
更多 icon
继续加载