有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何使用#Hibernate#Spring#Java在MySql中存储“日期”?

我正在开发一个具有CRUD功能的应用程序。当我从JSP文件添加日期值时,编译器抛出一个错误。我能够从数据库中推测日期的值,但这些值是手动添加的。我是如何向数据库中实际存储的用户添加日期值的

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]]

共 (0) 个答案