Field error in object ‘employee‘ on field ‘birth‘: rejected value [2017-11-11];

出现这个错误Field error in object ‘employee’ on field ‘birth’: rejected value [2017-11-11];
你可以尝试这样解决
当后台出现这个错误

Field error in object 'employee' on field 'birth': rejected value [2017-11-11]; codes [typeMismatch.employee.birth,typeMismatch.birth,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [employee.birth,birth]; arguments []; default message [birth]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'birth'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2017-11-11'; nested exception is java.lang.IllegalArgumentException]]

前端出现这个页面
在这里插入图片描述

导致这个原因的就是 前端默认输入的日期格式::yyyy/MM/dd
而我输入的格式却是: yyyy-MM-dd

最简单的方法 就是 改变一下格式
下面就是源代码
在IDEA中 键盘按下ctrl + shift + n:查找下面文件WebMvcAutoConfiguration
找到下面的代码方法点击进入,ctrl+左点击getDate()
在这里插入图片描述
你将会看到下面代码
在这里插入图片描述
ctrl+左点击date

在这里插入图片描述
默认的格式就是斜线的格式

你可以在springboot的配置文件 添加配置文件 并且在该实体类日期属性添加数据类型格式的注解
配置文件


spring:
  jackson:
    time-zone: GMT+8
    date-format: yyyy-MM-dd

在实体类属性添加数据类型格式的注解

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birth;

这样就修改完成了
仅作为参考 自学 也欢迎各位指正

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值