簡體   English   中英

如何將 spring 字段中的日期綁定到 pojo 類

[英]how to bind date in spring field to pojo class

  1. 我想將 spring 日期字段綁定到 pojo 類並返回日期
  2. dateOfbirth 是 java.sql.Date 類型。 現在,當我將日期從彈簧形式傳遞給函數 setDateOfBirth 時,它采用空值

例如在register.jsp (注冊表單)中,我有特定的字段

<form:label path="DateOfBirth">DateOfBirth</form:label>
<form:input path="DateOfBirth" type="date"/>

Register.java (Pojo 類)

 public void setDateOfBirth(Date dateOfBirth) {
   this.dateOfBirth = dateOfBirth   ;
 }

 public void getDateOfBirth() {
   return this.dateOfBirth;
 }

當我調用getDateOfBirth()
返回: Sat Dec 12 00:00:00 IST 1992

Input :- 12/12/1992

預期Output :- 12/12/1992

我得到的: null

請幫我如何轉換這個?

嘗試將@DateTimeFormat(pattern = "dd/MM/yyyy")Register.javadateOfBirth

@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date dateOfBirth;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM