我有一个插入/更新数据的表单。命令对象 (Bean) 类有一个 Date 字段,该字段以如下形式放置:
<form:hidden path="createdDate">
当我提交表单时,BindResult.hasErrors() 被验证为真。
我想我需要绑定日期对象,但是命令对象字段是怎么做的呢?
表单bean代码如下
@Entity
@Table(name = "Employee")
public class Employee {
@Id
@GeneratedValue
@Column(name="id")
private int id;
@Column(name="EmployeeName")
private String employeeName;
@Column(name="CreatedDate")
private Date createdDate;
//Setter and getter methods
}
错误:
[Field error in object 'employee' on field 'CreatedDate': rejected value [Mon Sep 17 20:35:26 IST 2012]; codes [typeMismatch.employee.CreatedDate,typeMismatch.CreatedDate,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [subject.CreatedDate,CreatedDate]; arguments []; default message [CreatedDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'CreatedDate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'CreatedDate': no matching editors or conversion strategy found]]