mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2026-01-13 13:21:11 +00:00
Use Java 8 LocalDate instead of java.util.Date
See gh-328
This commit is contained in:
parent
38bd3280cb
commit
c0748e3e82
5 changed files with 17 additions and 23 deletions
|
|
@ -15,9 +15,9 @@
|
|||
*/
|
||||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
|
@ -31,8 +31,6 @@ import javax.persistence.JoinColumn;
|
|||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.springframework.beans.support.MutableSortDefinition;
|
||||
import org.springframework.beans.support.PropertyComparator;
|
||||
|
|
@ -52,9 +50,8 @@ import org.springframework.samples.petclinic.visit.Visit;
|
|||
public class Pet extends NamedEntity {
|
||||
|
||||
@Column(name = "birth_date")
|
||||
@Temporal(TemporalType.DATE)
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date birthDate;
|
||||
private LocalDate birthDate;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "type_id")
|
||||
|
|
@ -67,11 +64,11 @@ public class Pet extends NamedEntity {
|
|||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "petId", fetch = FetchType.EAGER)
|
||||
private Set<Visit> visits = new LinkedHashSet<>();
|
||||
|
||||
public void setBirthDate(Date birthDate) {
|
||||
public void setBirthDate(LocalDate birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public Date getBirthDate() {
|
||||
public LocalDate getBirthDate() {
|
||||
return this.birthDate;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,13 +15,11 @@
|
|||
*/
|
||||
package org.springframework.samples.petclinic.visit;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDate;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
|
@ -38,9 +36,8 @@ import org.springframework.samples.petclinic.model.BaseEntity;
|
|||
public class Visit extends BaseEntity {
|
||||
|
||||
@Column(name = "visit_date")
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private Date date;
|
||||
private LocalDate date;
|
||||
|
||||
@NotEmpty
|
||||
@Column(name = "description")
|
||||
|
|
@ -53,14 +50,14 @@ public class Visit extends BaseEntity {
|
|||
* Creates a new instance of Visit for the current date
|
||||
*/
|
||||
public Visit() {
|
||||
this.date = new Date();
|
||||
this.date = LocalDate.now();
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
public LocalDate getDate() {
|
||||
return this.date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
public void setDate(LocalDate date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue