我正在开发具有CRUD功能的应用程序。当我从JSP文件添加DATE的值时,编译器将引发错误。我可以从数据库中获取DATE的值,但是这些值是手动添加的。我该如何添加实际存储在数据库中的用户的DATE值?
My Entity class:
@Entity`enter code here`
@Table(name="prefix_clients_tbl")
public class Clients {
@Temporal(TemporalType.DATE)
@Column(name="startdate")
private Date projectBeginingDate;
@Temporal(TemporalType.DATE)
@Column(name="enddate")
private Date projectEndDate;
public Date getProjectBeginingDate() {
return projectBeginingDate;
}
public Date getProjectEndDate() {
return projectEndDate;
}
public void setProjectBeginingDate(Date projectBeginingDate) {
this.projectBeginingDate = projectBeginingDate;
}
public void setProjectEndDate(Date projectEndDate) {
this.projectEndDate = projectEndDate;
}
@Override
public String toString() {
return "Clients [projectBeginingDate=" + projectBeginingDate + ", projectEndDate=" + projectEndDate + "]";
}
}
My JSP file:
<form:form name="NewClient" action="saveClient"
modelAttribute="client" method="POST">
<tr>
<td>PROJECT GIVEN DATE:</td>
<td><form:input type="text" path="projectBeginingDate"
id="mobilenumber" pattern="yyyy-MM-dd"/></td>
</tr>
<tr>
<td>EXPECTED DATE TO COMPLETE:</td>
<td><form:input type="text" path="projectEndDate"
id="mobilenumber" pattern="yyyy-MM-dd" /></td>
</tr>
</form:form>
My DataBase:
CREATE TABLE `prefix_clients_tbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(45) DEFAULT NULL,
`last_name` varchar(45) DEFAULT NULL,
`email` varchar(45) DEFAULT NULL,
`mobilenumber` int(13) DEFAULT NULL,
`city` varchar(45) DEFAULT NULL,
`country` varchar(45) DEFAULT NULL,
`domain` enum('Web-Development', 'Software Development','Application Development') DEFAULT NULL,
`requirments` text DEFAULT NULL,
`startdate` date DEFAULT NULL,
`enddate` date DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;
Field error in object 'client' on field 'projectBeginingDate': rejected value []; codes [typeMismatch.client.projectBeginingDate,typeMismatch.projectBeginingDate,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [client.projectBeginingDate,projectBeginingDate]; arguments []; default message [projectBeginingDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'projectBeginingDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.persistence.Temporal @javax.persistence.Column java.util.Date] for value ''; nested exception is java.lang.IllegalArgumentException]
Field error in object 'client' on field 'projectEndDate': rejected value []; codes [typeMismatch.client.projectEndDate,typeMismatch.projectEndDate,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [client.projectEndDate,projectEndDate]; arguments []; default message [projectEndDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'projectEndDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.persistence.Temporal @javax.persistence.Column java.util.Date] for value ''; nested exception is java.lang.IllegalArgumentException]]