mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 13:25:49 +00:00
improved code using lombok
This commit is contained in:
parent
f8a42d4f47
commit
88bbe1b280
10 changed files with 30 additions and 32 deletions
7
pom.xml
7
pom.xml
|
@ -58,10 +58,9 @@
|
|||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
||||
</dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
|
|
|
@ -21,8 +21,8 @@ import jakarta.persistence.GeneratedValue;
|
|||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object with an id property. Used as a base class for objects
|
||||
|
@ -32,7 +32,8 @@ import lombok.Getter;
|
|||
* @author Juergen Hoeller
|
||||
*/
|
||||
@MappedSuperclass
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
public class BaseEntity implements Serializable {
|
||||
|
||||
@Id
|
||||
|
|
|
@ -18,7 +18,9 @@ package org.springframework.samples.petclinic.model;
|
|||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object adds a name property to <code>BaseEntity</code>. Used as
|
||||
|
@ -29,17 +31,13 @@ import lombok.Data;
|
|||
* @author Wick Dynex
|
||||
*/
|
||||
@MappedSuperclass
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class NamedEntity extends BaseEntity {
|
||||
|
||||
@Column(name = "name")
|
||||
@NotBlank
|
||||
private String name;
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,8 @@ package org.springframework.samples.petclinic.model;
|
|||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object representing an person.
|
||||
|
@ -26,7 +27,8 @@ import lombok.Data;
|
|||
* @author Ken Krebs
|
||||
*/
|
||||
@MappedSuperclass
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
public class Person extends BaseEntity {
|
||||
|
||||
@Column(name = "first_name")
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
|
@ -46,7 +46,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|||
* @author Wick Dynex
|
||||
*/
|
||||
@Controller
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
class OwnerController {
|
||||
|
||||
private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
|
||||
|
|
|
@ -32,7 +32,6 @@ import jakarta.persistence.ManyToOne;
|
|||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OrderBy;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
/**
|
||||
|
@ -42,6 +44,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|||
*/
|
||||
@Controller
|
||||
@RequestMapping("/owners/{ownerId}")
|
||||
@RequiredArgsConstructor
|
||||
class PetController {
|
||||
|
||||
private static final String VIEWS_PETS_CREATE_OR_UPDATE_FORM = "pets/createOrUpdatePetForm";
|
||||
|
@ -50,11 +53,6 @@ class PetController {
|
|||
|
||||
private final PetTypeRepository types;
|
||||
|
||||
public PetController(OwnerRepository owners, PetTypeRepository types) {
|
||||
this.owners = owners;
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
@ModelAttribute("types")
|
||||
public Collection<PetType> populatePetTypes() {
|
||||
return this.types.findPetTypes();
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.springframework.samples.petclinic.owner;
|
|||
import org.springframework.format.Formatter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
@ -33,13 +35,12 @@ import java.util.Locale;
|
|||
* @author Michael Isvy
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class PetTypeFormatter implements Formatter<PetType> {
|
||||
|
||||
private final PetTypeRepository types;
|
||||
|
||||
public PetTypeFormatter(PetTypeRepository types) {
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String print(PetType petType, Locale locale) {
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
|
@ -41,7 +41,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|||
* @author Wick Dynex
|
||||
*/
|
||||
@Controller
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
class VisitController {
|
||||
|
||||
private final OwnerRepository owners;
|
||||
|
|
|
@ -26,6 +26,8 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Mark Fisher
|
||||
|
@ -33,13 +35,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|||
* @author Arjen Poutsma
|
||||
*/
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
class VetController {
|
||||
|
||||
private final VetRepository vetRepository;
|
||||
|
||||
public VetController(VetRepository vetRepository) {
|
||||
this.vetRepository = vetRepository;
|
||||
}
|
||||
|
||||
@GetMapping("/vets.html")
|
||||
public String showVetList(@RequestParam(defaultValue = "1") int page, Model model) {
|
||||
|
|
Loading…
Reference in a new issue