简体   繁体   English

java.sql.Time:正确插入当前时间

[英]java.sql.Time : insert current time correctly

I'm trying to insert current time into a java.sql.Time field, but I get this exception: 我试图将当前时间插入到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]

This is the code: 这是代码:

firm.setEntryDate(Time.valueOf(java.time.LocalDate.now().toString()));

Can anybody please advise what I am doing wrong? 有人可以告诉我我在做什么错吗? Thanks! 谢谢!

Update: Firm.class 更新: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;
}

Full exception: 完全例外:

 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()));

Use timeStamp 使用时间戳

private TimeStamp entryDate; 私人时间戳记entryDate;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM