【发布时间】:2017-06-21 12:52:59
【问题描述】:
我正在尝试将当前时间插入到 java.sql.Time 字段中,但我得到了这个异常:
default message [Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Time' for property 'entryDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.sql.Time] for value ''; nested exception is java.lang.IllegalArgumentException]
这是代码:
firm.setEntryDate(Time.valueOf(java.time.LocalDate.now().toString()));
谁能告诉我我做错了什么?谢谢!
更新:Firm.class
@JsonProperty("webshow")
private String webShow;
private Time entryDate;
public String getWebShow () {
return webShow;
}
public void setWebShow (String webShow) {
this.webShow = webShow;
}
public Time getEntryDate () {
return entryDate;
}
public void setEntryDate (Time entryDate) {
this.entryDate = entryDate;
}
完全例外:
Resolved exception caused by Handler execution: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'firm' on field 'entryDate': rejected value []; codes [typeMismatch.firm.entryDate,typeMismatch.entryDate,typeMismatch.java.sql.Time,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [firm.entryDate,entryDate]; arguments []; default message [entryDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Time' for property 'entryDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.sql.Time] for value ''; nested exception is java.lang.IllegalArgumentException]
【问题讨论】:
-
尝试删除
.toString()并查看 -
@niceman
firm.setEntryDate(Time.valueOf(java.time.LocalTime.now()));我不得不将其更改为 LocalTime 而不是 LocalDate -
@niceman 它在
Time.valueOf里面,需要一个字符串 -
你是不是真的是抛出的那条线,而不是
firm.setEntryDate里面的东西? -
我认为这与您的二传手没有任何关系。似乎 spring 正在尝试转换某些东西。它在转换什么?