【发布时间】:2018-11-21 12:44:55
【问题描述】:
所以我有这个支付历史数据库,它的属性之一是时间戳类型的时间 (YYYY-MM-DD HH:MM:SS)。我需要制作表格以添加新的付款历史记录。我的控制器将自动捕获付款历史对象并将其添加到数据库中。但由于我在 HTML 中的时间格式(我选择本地日期时间)与 DB 中的时间格式不匹配,我无法继续添加我的新付款历史记录。
这是我的错误:
Field error in object 'paymentHistoryModel' on field 'time': rejected value
[2019-02-03T15:02]; codes
[typeMismatch.paymentHistoryModel.time,typeMismatch.time,
typeMismatch.java.sql.Timestamp,typeMismatch]; arguments
[org.springframework.context.support.DefaultMessageSourceResolvable: codes
[paymentHistoryModel.time,time]; arguments []; default message [time]];
default message [Failed to convert property value of type 'java.lang.String' to
required type 'java.sql.Timestamp' for property 'time'; nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to convert
from type [java.lang.String] to type [@javax.validation.constraints.NotNull
@javax.persistence.Column java.sql.Timestamp] for value '2019-02-03T15:02';
nested exception is java.lang.IllegalArgumentException: Timestamp format must
be yyyy-mm-dd hh:mm:ss[.fffffffff]]
有没有办法在我的数据库中创建具有精确格式(如时间戳)的 HTML 输入?谢谢!!
【问题讨论】:
-
您需要自己解析字符串,即在您的代码中。如果没有更多信息,尤其是一些代码(请记住,它应该很短,最好是 minimal reproducible example),很难说出更多信息。
-
欢迎来到 SO!根据错误消息,您输入的时间戳是“2019-02-03T15:02”,这当然与您的格式“YYYY-MM-DD HH:MM:SS”不匹配。