This commit is contained in:
nirsa 2025-04-03 14:40:51 +09:00
parent 0bacd0367f
commit efff33c609
5 changed files with 10836 additions and 7619 deletions

View file

@ -0,0 +1,13 @@
package org.springframework.samples.petclinic;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringPetclinicApplication {
public static void main(String[] args) {
SpringApplication.run(SpringPetclinicApplication.class, args);
}
}

View file

@ -30,8 +30,8 @@ import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import jakarta.persistence.OrderBy; import jakarta.persistence.OrderBy;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
/** /**
* Simple JavaBean domain object representing an owner. * Simple JavaBean domain object representing an owner.
@ -94,7 +94,7 @@ public class Owner extends Person {
} }
public void addPet(Pet pet) { public void addPet(Pet pet) {
if (pet.isNew()) { if (pet != null && pet.isNew()) {
getPets().add(pet); getPets().add(pet);
} }
} }
@ -117,11 +117,12 @@ public class Owner extends Person {
for (Pet pet : getPets()) { for (Pet pet : getPets()) {
if (!pet.isNew()) { if (!pet.isNew()) {
Integer compId = pet.getId(); Integer compId = pet.getId();
if (compId.equals(id)) { if (compId != null && compId.equals(id)) {
return pet; return pet;
} }
} }
} }
return null; return null;
} }
@ -132,6 +133,8 @@ public class Owner extends Person {
* @return the Pet with the given name, or null if no such Pet exists for this Owner * @return the Pet with the given name, or null if no such Pet exists for this Owner
*/ */
public Pet getPet(String name, boolean ignoreNew) { public Pet getPet(String name, boolean ignoreNew) {
if (name == null) return null;
for (Pet pet : getPets()) { for (Pet pet : getPets()) {
String compName = pet.getName(); String compName = pet.getName();
if (compName != null && compName.equalsIgnoreCase(name)) { if (compName != null && compName.equalsIgnoreCase(name)) {

View file

@ -90,7 +90,7 @@ class OwnerController {
} }
@GetMapping("/owners") @GetMapping("/owners")
public String processFindForm(@RequestParam(name="page", defaultValue = "1") int page, Owner owner, BindingResult result, public String processFindForm(@RequestParam(defaultValue = "1") int page, Owner owner, BindingResult result,
Model model) { Model model) {
// allow parameterless GET request for /owners to return all records // allow parameterless GET request for /owners to return all records
if (owner.getLastName() == null) { if (owner.getLastName() == null) {

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,13 @@
package org.springframework.samples.petclinic;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class SpringPetclinicApplicationTests {
@Test
void contextLoads() {
}
}