2016-06-17 16 views
1

をゼロのちょうどYYYY-MM-DDを招くことなく、私は春のブートアプリケーションでSQL DBで働いています。 1)SQL型DATEとフォーマットYYYY-MM-DD。@DateTimeFormatterマイSQL春とブート

2)私は一時的なタイプを使用する場合、それは適切な形式でデータを引き出しますが、編集を行うと、操作を追加しながら、それを許可していないようです。

3)私は、DateTimeのフォーマッタを使用する場合、すべての操作が正常に動作しますが、データはプルアップ、または先行ゼロのアプリケーションで私は自分のアプリケーションのためたくないと追加されています。 Employee.java

@DateTimeFormat(pattern = "yyyy-MM-dd") 
    @Column(name="birth_date") 
    @NotNull @Past 
// @Temporal(TemporalType.DATE) 
    private Date birthDate; 



    @DateTimeFormat(pattern = "yyyy-MM-dd") 
    @Column(name="hire_date") 
    @NotNull 
// @Temporal(TemporalType.DATE) 
    private Date hireDate; 

何ができるのか助言、と私はLOCALDATEにタイプを変更したときに追加してください、それはロケールの日付の変換をサポートしているので、ジョダの依存関係がうまくいくの追加

There was an unexpected error (type=Internal Server Error, status=500). 
could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize 

答えて

1

をスローし、マッピングは、SQLごととして適切であろう、とゼロのちょうどYYYY-MM-DDをリード/タイムスタンプのないすなわち日付のみ、(MySQLの上で)DATEとしてマッピングされます。 は、エンティティ・クラスへのpom.xml

 <dependency> 
    <groupId>joda-time</groupId> 
    <artifactId>joda-time</artifactId> 
</dependency> 

<dependency> 
    <groupId>org.jadira.usertype</groupId> 
    <artifactId>usertype.core</artifactId> 
    <version>3.1.0.CR1</version> 
</dependency> 

<dependency> 
    <groupId>joda-time</groupId> 
    <artifactId>joda-time-hibernate</artifactId> 
    <version>1.3</version> 
</dependency> 
<dependency> 
     <groupId>joda-time</groupId> 
     <artifactId>joda-time-jsptags</artifactId> 
     <version>1.1.1</version> 
</dependency> 

し、この中で、この中にこれらを追加します。

@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate") 
@DateTimeFormat(pattern = "yyyy-MM-dd") 
@Column(name="birth_date") 
@NotNull 
private LocalDate birthDate;` 

public LocalDate getBirthDate() { 
    return this.birthDate; 
} 

public void setBirthDate(LocalDate birthDate) { 
    this.birthDate = birthDate; 
}` 
+0

感謝!!!!できます ! :) :) –

関連する問題