如何将spring字段中的日期绑定到pojo类 我想将spring日期字段绑定到pojo类并返回日期 dateOfbirth的类型为java.sql.Date。现在,当我将日期从spring表单传递到函数setDateOfBirth时,它取空值
例如,在register.jsp(注册表)中,我有一个特定的字段如何将spring字段中的日期绑定到pojo类 我想将spring日期字段绑定到pojo类并返回日期 dateOfbirth的类型为java.sql.Date。现在,当我将日期从spring表单传递到函数setDateOfBirth时,它取空值,java,spring,jsp,Java,Spring,Jsp,例如,在register.jsp(注册表)中,我有一个特定的字段 <form:label path="DateOfBirth">DateOfBirth</form:label> <form:input path="DateOfBirth" type="date"/> 当我调用getDateOfBirth() 返回:1992年12月12日星期六00:00:00 IST Input :- 12/12/1992 预期输出:-12/12/1992 我得到的:nul
<form:label path="DateOfBirth">DateOfBirth</form:label>
<form:input path="DateOfBirth" type="date"/>
当我调用getDateOfBirth()返回:
1992年12月12日星期六00:00:00 IST
Input :- 12/12/1992
预期输出:-12/12/1992
我得到的:null
请帮助我如何转换此值?请尝试在Register.java中添加到您的出生日期
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date dateOfBirth;
在这种情况下,可能的重复应该使用字符串而不是日期,因为日期应该是日期,而不是某个格式化的日期。要获取格式化的日期,请在视图上使用SimpleDataFormat或jstl标记。链接结果的格式为:Sat Dec 12 00:00:00 IST 1992。但是我想在1992年12月12日得到结果,我想插入sql日期。所以我在Register.java中将dateOfBirth定义为java.sql.Date。当我调用getDateOfBirth()时,它给我null。
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date dateOfBirth;