首页 > 解决方案 > 前台String类型的时间字符串是否异常传输到后台?

问题描述

我在前台根据时间进行查询操作,将时间字符串“2020-08-02 12:30:30”传给后台,后台控制台抛出这个错误:

提示信息:

default message [Failed to convert property value of type'java.lang.String' to required type'java.util.Date' for property'scanTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.format.annotation.DateTimeFormat java.util.Date] for value '2020-08-02 12:30:30'; nested exception is java.lang.IllegalArgumentException : Invalid format: "2020-08-02 12:30:30" is malformed at "12:30:30"]

数据库中的该字段是日期类型。我用了"@DateTimeFormat(iso=DateTimeFormat.ISO.DATE)"前台的注解。为什么会出现这个错误?

@DateTimeFormat(iso=DateTimeFormat.ISO.DATE) 
private Date scanTime;

标签: javastringdate

解决方案


推荐阅读