[英]how to bind date in spring field to pojo class
For example in register.jsp (Registration form) I have the particular field例如在register.jsp (注册表单)中,我有特定的字段
<form:label path="DateOfBirth">DateOfBirth</form:label>
<form:input path="DateOfBirth" type="date"/>
Register.java (Pojo class) Register.java (Pojo 类)
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth ;
}
public void getDateOfBirth() {
return this.dateOfBirth;
}
when I call getDateOfBirth()当我调用getDateOfBirth()
returns: Sat Dec 12 00:00:00 IST 1992
返回:
Sat Dec 12 00:00:00 IST 1992
Input :- 12/12/1992
Expected Output :- 12/12/1992
预期
Output :- 12/12/1992
What I get: null
我得到的:
null
Please help me how to convert this ?请帮我如何转换这个?
Try to add @DateTimeFormat(pattern = "dd/MM/yyyy")
to your dateOfBirth
in Register.java
尝试将
@DateTimeFormat(pattern = "dd/MM/yyyy")
到Register.java
的dateOfBirth
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date dateOfBirth;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.