diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Pet.java b/src/main/java/org/springframework/samples/petclinic/owner/Pet.java index 5e226a180388028598146bf273af481a528a9ad0..795e2a94eefbc817b21132770e31f72d3f476e06 100755 --- a/src/main/java/org/springframework/samples/petclinic/owner/Pet.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/Pet.java @@ -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; } diff --git a/src/main/java/org/springframework/samples/petclinic/visit/Visit.java b/src/main/java/org/springframework/samples/petclinic/visit/Visit.java index ce10d7b127e8ac4b532fbc1054ed1589fac8c272..d21f60dfc1b70ad7dc4f0b35a4a3d10e23762224 100755 --- a/src/main/java/org/springframework/samples/petclinic/visit/Visit.java +++ b/src/main/java/org/springframework/samples/petclinic/visit/Visit.java @@ -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; } diff --git a/src/main/resources/templates/owners/ownerDetails.html b/src/main/resources/templates/owners/ownerDetails.html index 746d569be29a95feea5d9bebd25ddd1cf80784da..ed89462b339675c679f1d4f18036e7c4ddfd3121 100644 --- a/src/main/resources/templates/owners/ownerDetails.html +++ b/src/main/resources/templates/owners/ownerDetails.html @@ -47,7 +47,7 @@ <dd th:text="${pet.name}" /></dd> <dt>Birth Date</dt> <dd - th:text="${#calendars.format(pet.birthDate, 'yyyy-MM-dd')}" /></dd> + th:text="${#temporals.format(pet.birthDate, 'yyyy-MM-dd')}" /></dd> <dt>Type</dt> <dd th:text="${pet.type}" /></dd> </dl> @@ -61,7 +61,7 @@ </tr> </thead> <tr th:each="visit : ${pet.visits}"> - <td th:text="${#calendars.format(visit.date, 'yyyy-MM-dd')}"></td> + <td th:text="${#temporals.format(visit.date, 'yyyy-MM-dd')}"></td> <td th:text="${visit?.description}"></td> </tr> <tr> @@ -80,4 +80,4 @@ </body> -</html> \ No newline at end of file +</html> diff --git a/src/main/resources/templates/pets/createOrUpdateVisitForm.html b/src/main/resources/templates/pets/createOrUpdateVisitForm.html index 4401d36ce13519a89cf67679606b3027e02c751a..609a735f98c71b431dbf2f37200a6e834a3f0deb 100644 --- a/src/main/resources/templates/pets/createOrUpdateVisitForm.html +++ b/src/main/resources/templates/pets/createOrUpdateVisitForm.html @@ -21,7 +21,7 @@ <tr> <td th:text="${pet.name}" /></td> <td - th:text="${#calendars.format(pet.birthDate, 'yyyy-MM-dd')}" /></td> + th:text="${#temporals.format(pet.birthDate, 'yyyy-MM-dd')}" /></td> <td th:text="${pet.type}" /></td> <td th:text="${pet.owner?.firstName + ' ' + pet.owner?.lastName}" /></td> @@ -52,10 +52,10 @@ <th>Description</th> </tr> <tr th:if="${!visit['new']}" th:each="visit : ${pet.visits}"> - <td th:text="${#calendars.format(visit.date, 'yyyy-MM-dd')}" /></td> + <td th:text="${#temporals.format(visit.date, 'yyyy-MM-dd')}" /></td> <td th:text=" ${visit.description}" /></td> </tr> </table> </body> -</html> \ No newline at end of file +</html> diff --git a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java index 7ed5bf8a57d24044d1b227547688eac7f4e2b20e..6ea694120cbf29f48d7e4596f789c5dd0fcf6866 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java @@ -2,8 +2,8 @@ package org.springframework.samples.petclinic.service; import static org.assertj.core.api.Assertions.assertThat; +import java.time.LocalDate; import java.util.Collection; -import java.util.Date; import org.junit.Test; import org.junit.runner.RunWith; @@ -140,7 +140,7 @@ public class ClinicServiceTests { pet.setName("bowser"); Collection<PetType> types = this.pets.findPetTypes(); pet.setType(EntityUtils.getById(types, PetType.class, 2)); - pet.setBirthDate(new Date()); + pet.setBirthDate(LocalDate.now()); owner6.addPet(pet); assertThat(owner6.getPets().size()).isEqualTo(found + 1);