日期格式化出错

错误报告:

Field error in object 'employee' on field 'birth': rejected value [1999-6-21]; 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 '1999-6-21'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [1999-6-21]]]
Employee{id=1001, lastName='E-AA', email='aa@163.com', gender=1, department=Department [id=101, departmentName=D-AA], birth=Fri Aug 28 16:17:56 CST 2020}

错误原因:springmvc将页面提交的值转换为指定类型,即转换前可以设置类型格式(默认的是用dd/MM/yyyy)
我们则可以通过配置文件application.properties来修改这个默认格式

spring.mvc.format.date=yyyy/MM/dd

而我原来使用的
在这里插入图片描述
因为多加了个空格导致无法生效,且原来的默认配置覆盖掉,在输入时必须要用yyyy/MM/dd HH:mm默认的格式输入才行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值