From 2cadb48a00e12f813f5b86fdd94d62f5d8d531d2 Mon Sep 17 00:00:00 2001 From: Nguyen Tuan Khiem Date: Mon, 9 Feb 2026 16:16:38 +0700 Subject: [PATCH] feature: refactor code --- .editorconfig | 10 +- pom.xml | 807 +++++++++--------- .../samples/petclinic/model/BaseEntity.java | 12 +- .../samples/petclinic/model/NamedEntity.java | 12 +- .../samples/petclinic/model/Person.java | 22 +- .../samples/petclinic/owner/Owner.java | 32 +- .../samples/petclinic/owner/Pet.java | 20 +- .../samples/petclinic/owner/Visit.java | 20 +- .../resources/messages/messages.properties | 2 +- .../resources/templates/fragments/layout.html | 130 +-- .../templates/owners/findOwners.html | 4 +- 11 files changed, 511 insertions(+), 560 deletions(-) diff --git a/.editorconfig b/.editorconfig index 4e509a427..e3bbef05c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,7 +5,9 @@ root = true charset = utf-8 end_of_line = lf insert_final_newline = true -indent_style = space +indent_style = tab +tab_width = 4 +indent_size = 4 [*.{java,xml}] indent_size = 4 @@ -14,11 +16,11 @@ indent_style = tab tab_width = 4 [{pom,wro}.xml] -indent_size = 2 -indent_style = space +indent_size = 4 +indent_style = tab [*.{html,sql,less}] -indent_size = 2 +indent_size = 4 [*.gradle] indent_size = 2 diff --git a/pom.xml b/pom.xml index fb38cc3db..39e3df572 100644 --- a/pom.xml +++ b/pom.xml @@ -1,411 +1,422 @@ - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 4.0.1 - - org.springframework.samples - spring-petclinic - 4.0.0-SNAPSHOT - petclinic + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 4.0.1 + + org.springframework.samples + spring-petclinic + 4.0.0-SNAPSHOT + petclinic - - - 17 - UTF-8 - UTF-8 - - 2024-11-28T14:37:52Z + + + 17 + UTF-8 + UTF-8 + + 2024-11-28T14:37:52Z - - 1.1.2 - 5.3.8 - 4.7.0 + + 1.1.2 + 5.3.8 + 4.7.0 - 12.1.2 - 0.8.14 - 0.3.4 - 1.0.0 - 3.6.0 - 0.0.11 - 0.0.47 - + 12.1.2 + 0.8.14 + 0.3.4 + 1.0.0 + 3.6.0 + 0.0.11 + 0.0.47 + - - - Apache License, Version 2.0 - https://www.apache.org/licenses/LICENSE-2.0 - - + + + Apache License, Version 2.0 + https://www.apache.org/licenses/LICENSE-2.0 + + - - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-cache - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - org.springframework.boot - spring-boot-starter-validation - - - org.springframework.boot - spring-boot-starter-webmvc - + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-cache + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-webmvc + - - javax.cache - cache-api - - - jakarta.xml.bind - jakarta.xml.bind-api - + + javax.cache + cache-api + + + jakarta.xml.bind + jakarta.xml.bind-api + - - com.h2database - h2 - runtime - - - com.github.ben-manes.caffeine - caffeine - runtime - - - com.mysql - mysql-connector-j - runtime - - - org.postgresql - postgresql - runtime - - - org.webjars - webjars-locator-lite - ${webjars-locator.version} - runtime - - - org.webjars.npm - bootstrap - ${webjars-bootstrap.version} - runtime - - - org.webjars.npm - font-awesome - ${webjars-font-awesome.version} - runtime - + + com.h2database + h2 + runtime + + + com.github.ben-manes.caffeine + caffeine + runtime + + + com.mysql + mysql-connector-j + runtime + + + org.postgresql + postgresql + runtime + + + org.webjars + webjars-locator-lite + ${webjars-locator.version} + runtime + + + org.webjars.npm + bootstrap + ${webjars-bootstrap.version} + runtime + + + org.webjars.npm + font-awesome + ${webjars-font-awesome.version} + runtime + - - org.springframework.boot - spring-boot-devtools - true - + + org.springframework.boot + spring-boot-devtools + true + - - org.springframework.boot - spring-boot-starter-data-jpa-test - test - - - org.springframework.boot - spring-boot-starter-restclient-test - test - - - org.springframework.boot - spring-boot-starter-webmvc-test - test - - - org.springframework.boot - spring-boot-testcontainers - test - - - org.springframework.boot - spring-boot-docker-compose - test - - - org.testcontainers - testcontainers-junit-jupiter - test - - - org.testcontainers - testcontainers-mysql - test - - + + org.springframework.boot + spring-boot-starter-data-jpa-test + test + + + org.springframework.boot + spring-boot-starter-restclient-test + test + + + org.springframework.boot + spring-boot-starter-webmvc-test + test + + + org.springframework.boot + spring-boot-testcontainers + test + + + org.springframework.boot + spring-boot-docker-compose + test + + + org.testcontainers + testcontainers-junit-jupiter + test + + + org.testcontainers + testcontainers-mysql + test + + + org.projectlombok + lombok + annotationProcessor + + - - - - org.apache.maven.plugins - maven-enforcer-plugin - - - enforce-java - - enforce - - - - - This build requires at least Java ${java.version}, update your JVM, and run the build again - ${java.version} - - - - - - - - io.spring.javaformat - spring-javaformat-maven-plugin - ${spring-format.version} - - - - validate - - validate - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - ${maven-checkstyle.version} - - - com.puppycrawl.tools - checkstyle - ${checkstyle.version} - - - io.spring.nohttp - nohttp-checkstyle - ${nohttp-checkstyle.version} - - - - - nohttp-checkstyle-validation - - check - - validate - - src/checkstyle/nohttp-checkstyle.xml - ${basedir} - **/* - **/.git/**/*,**/.idea/**/*,**/target/**/,**/.flattened-pom.xml,**/*.class - config_loc=${basedir}/src/checkstyle/ - - - - - - org.graalvm.buildtools - native-maven-plugin - - - org.springframework.boot - spring-boot-maven-plugin - - - - - build-info - - - - ${project.build.sourceEncoding} - ${project.reporting.outputEncoding} - ${java.version} - ${java.version} - - - - - - - org.jacoco - jacoco-maven-plugin - ${jacoco.version} - - - - prepare-agent - - - - report - - report - - prepare-package - - - + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + enforce-java + + enforce + + + + + This build requires at least Java ${java.version}, update your JVM, and run + the build again + + ${java.version} + + + + + + + + io.spring.javaformat + spring-javaformat-maven-plugin + ${spring-format.version} + + + + validate + + validate + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle.version} + + + com.puppycrawl.tools + checkstyle + ${checkstyle.version} + + + io.spring.nohttp + nohttp-checkstyle + ${nohttp-checkstyle.version} + + + + + nohttp-checkstyle-validation + + check + + validate + + src/checkstyle/nohttp-checkstyle.xml + ${basedir} + **/* + **/.git/**/*,**/.idea/**/*,**/target/**/,**/.flattened-pom.xml,**/*.class + + config_loc=${basedir}/src/checkstyle/ + + + + + + org.graalvm.buildtools + native-maven-plugin + + + org.springframework.boot + spring-boot-maven-plugin + + + + + build-info + + + + ${project.build.sourceEncoding} + ${project.reporting.outputEncoding} + ${java.version} + ${java.version} + + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + + prepare-agent + + + + report + + report + + prepare-package + + + - - - io.github.git-commit-id - git-commit-id-maven-plugin - - false - false - - - - - - org.cyclonedx - cyclonedx-maven-plugin - - - - - - css - - - - org.apache.maven.plugins - maven-dependency-plugin - - - unpack - - unpack - - - generate-resources - - - - org.webjars.npm - bootstrap - ${webjars-bootstrap.version} - - - ${project.build.directory}/webjars - - - - - - com.gitlab.haynes - libsass-maven-plugin - ${libsass.version} - - ${basedir}/src/main/scss/ - ${basedir}/src/main/resources/static/resources/css/ - ${project.build.directory}/webjars/META-INF/resources/webjars/bootstrap/${webjars-bootstrap.version}/scss/ - - - - - - compile - - generate-resources - - - - - - - - m2e - - - m2e.version - - - - - - - - org.eclipse.m2e - lifecycle-mapping - ${lifecycle-mapping} - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - [1,) - - check - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - [1,) - - build-info - - - - - - - - - io.spring.javaformat - spring-javaformat-maven-plugin - [0,) - - validate - - - - - - - - - - - - - - - + + + io.github.git-commit-id + git-commit-id-maven-plugin + + false + false + + + + + + org.cyclonedx + cyclonedx-maven-plugin + + + + + + css + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack + + unpack + + + generate-resources + + + + org.webjars.npm + bootstrap + ${webjars-bootstrap.version} + + + ${project.build.directory}/webjars + + + + + + com.gitlab.haynes + libsass-maven-plugin + ${libsass.version} + + ${basedir}/src/main/scss/ + ${basedir}/src/main/resources/static/resources/css/ + + ${project.build.directory}/webjars/META-INF/resources/webjars/bootstrap/${webjars-bootstrap.version}/scss/ + + + + + + + compile + + generate-resources + + + + + + + + m2e + + + m2e.version + + + + + + + + org.eclipse.m2e + lifecycle-mapping + ${lifecycle-mapping} + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + [1,) + + check + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + [1,) + + build-info + + + + + + + + + io.spring.javaformat + spring-javaformat-maven-plugin + [0,) + + validate + + + + + + + + + + + + + + + diff --git a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java b/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java index 6babed56d..7c27c2418 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java +++ b/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java @@ -21,6 +21,8 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.MappedSuperclass; +import lombok.Getter; +import lombok.Setter; /** * Simple JavaBean domain object with an id property. Used as a base class for objects @@ -30,20 +32,14 @@ import jakarta.persistence.MappedSuperclass; * @author Juergen Hoeller */ @MappedSuperclass +@Getter +@Setter public class BaseEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - public boolean isNew() { return this.id == null; } diff --git a/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java b/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java index 61e882a95..5e4db85f3 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java +++ b/src/main/java/org/springframework/samples/petclinic/model/NamedEntity.java @@ -18,6 +18,8 @@ package org.springframework.samples.petclinic.model; import jakarta.persistence.Column; import jakarta.persistence.MappedSuperclass; import jakarta.validation.constraints.NotBlank; +import lombok.Getter; +import lombok.Setter; /** * Simple JavaBean domain object adds a name property to BaseEntity. Used as @@ -28,20 +30,14 @@ import jakarta.validation.constraints.NotBlank; * @author Wick Dynex */ @MappedSuperclass +@Getter +@Setter public class NamedEntity extends BaseEntity { @Column @NotBlank private String name; - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - @Override public String toString() { String name = this.getName(); diff --git a/src/main/java/org/springframework/samples/petclinic/model/Person.java b/src/main/java/org/springframework/samples/petclinic/model/Person.java index 30b5829d8..734a326dc 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Person.java +++ b/src/main/java/org/springframework/samples/petclinic/model/Person.java @@ -18,6 +18,8 @@ package org.springframework.samples.petclinic.model; import jakarta.persistence.Column; import jakarta.persistence.MappedSuperclass; import jakarta.validation.constraints.NotBlank; +import lombok.Getter; +import lombok.Setter; /** * Simple JavaBean domain object representing an person. @@ -25,6 +27,8 @@ import jakarta.validation.constraints.NotBlank; * @author Ken Krebs */ @MappedSuperclass +@Getter +@Setter public class Person extends BaseEntity { @Column @@ -34,21 +38,5 @@ public class Person extends BaseEntity { @Column @NotBlank private String lastName; - - public String getFirstName() { - return this.firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return this.lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - + } diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java index 480a7a690..cd3b9d6b0 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java @@ -19,6 +19,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import lombok.Getter; +import lombok.Setter; import org.springframework.core.style.ToStringCreator; import org.springframework.samples.petclinic.model.Person; import org.springframework.util.Assert; @@ -46,6 +48,8 @@ import jakarta.validation.constraints.NotBlank; */ @Entity @Table(name = "owners") +@Getter +@Setter public class Owner extends Person { @Column @@ -66,34 +70,6 @@ public class Owner extends Person { @OrderBy("name") private final List pets = new ArrayList<>(); - public String getAddress() { - return this.address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getCity() { - return this.city; - } - - public void setCity(String city) { - this.city = city; - } - - public String getTelephone() { - return this.telephone; - } - - public void setTelephone(String telephone) { - this.telephone = telephone; - } - - public List getPets() { - return this.pets; - } - public void addPet(Pet pet) { if (pet.isNew()) { getPets().add(pet); 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 4f8409ef2..7d404cbb0 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/Pet.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/Pet.java @@ -20,6 +20,8 @@ import java.util.Collection; import java.util.LinkedHashSet; import java.util.Set; +import lombok.Getter; +import lombok.Setter; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.samples.petclinic.model.NamedEntity; @@ -43,6 +45,8 @@ import jakarta.persistence.Table; */ @Entity @Table(name = "pets") +@Getter +@Setter public class Pet extends NamedEntity { @Column @@ -58,22 +62,6 @@ public class Pet extends NamedEntity { @OrderBy("date ASC") private final Set visits = new LinkedHashSet<>(); - public void setBirthDate(LocalDate birthDate) { - this.birthDate = birthDate; - } - - public LocalDate getBirthDate() { - return this.birthDate; - } - - public PetType getType() { - return this.type; - } - - public void setType(PetType type) { - this.type = type; - } - public Collection getVisits() { return this.visits; } diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Visit.java b/src/main/java/org/springframework/samples/petclinic/owner/Visit.java index 085cd2849..f365ff41e 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/Visit.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/Visit.java @@ -17,6 +17,8 @@ package org.springframework.samples.petclinic.owner; import java.time.LocalDate; +import lombok.Getter; +import lombok.Setter; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.samples.petclinic.model.BaseEntity; @@ -33,6 +35,8 @@ import jakarta.validation.constraints.NotBlank; */ @Entity @Table(name = "visits") +@Getter +@Setter public class Visit extends BaseEntity { @Column(name = "visit_date") @@ -49,20 +53,4 @@ public class Visit extends BaseEntity { this.date = LocalDate.now(); } - public LocalDate getDate() { - return this.date; - } - - public void setDate(LocalDate date) { - this.date = date; - } - - public String getDescription() { - return this.description; - } - - public void setDescription(String description) { - this.description = description; - } - } diff --git a/src/main/resources/messages/messages.properties b/src/main/resources/messages/messages.properties index 193565895..bdb9b8e81 100644 --- a/src/main/resources/messages/messages.properties +++ b/src/main/resources/messages/messages.properties @@ -1,4 +1,4 @@ -welcome=Welcome +welcome=Welcome home required=is required notFound=has not been found duplicate=is already in use diff --git a/src/main/resources/templates/fragments/layout.html b/src/main/resources/templates/fragments/layout.html index 7c5cd0d86..160f64d57 100644 --- a/src/main/resources/templates/fragments/layout.html +++ b/src/main/resources/templates/fragments/layout.html @@ -4,85 +4,91 @@ - - - - - - PetClinic :: a Spring Framework demonstration - - + + + + + + PetClinic :: a Spring Framework demonstration + + - +
+
-
-
-
-
-
- -
-
-
-
-
+ - +
+
+
+
+
+ +
+
+
+ + + + - \ No newline at end of file + diff --git a/src/main/resources/templates/owners/findOwners.html b/src/main/resources/templates/owners/findOwners.html index 703351c7d..131786af4 100644 --- a/src/main/resources/templates/owners/findOwners.html +++ b/src/main/resources/templates/owners/findOwners.html @@ -1,6 +1,6 @@ - + @@ -32,4 +32,4 @@ - \ No newline at end of file +