java.sql.Time : 正确插入当前时间
java.sql.Time : insert current time correctly
我正在尝试将当前时间插入到 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]
试试这个:
firm.setEntryDate(java.sql.Time.valueOf(LocalTime.now()));
使用时间戳
私有时间戳入口日期;
我正在尝试将当前时间插入到 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]
试试这个:
firm.setEntryDate(java.sql.Time.valueOf(LocalTime.now()));
使用时间戳
私有时间戳入口日期;