diff --git a/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java index 00747709a..333f717b1 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java @@ -124,11 +124,6 @@ class OwnerController { return "owners/ownersList"; } - // private Page findPaginatedForOwnersLastName(int page, String lastname) { - // int pageSize = 5; - // Pageable pageable = PageRequest.of(page - 1, pageSize); - // return owners.findByLastNameStartingWith(lastname, pageable); - // } private Page findPaginatedForOwnersName(int page, String lastname) { int pageSize = 5; Pageable pageable = PageRequest.of(page - 1, pageSize); diff --git a/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java b/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java index ee6ba4222..fd5e3af41 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java @@ -54,7 +54,7 @@ public interface OwnerRepository extends JpaRepository { * @return a Collection of matching {@link Owner}s (or an empty Collection if none * found) */ - // Page findByLastNameStartingWith(String lastName, Pageable pageable); + @Query("SELECT o FROM Owner o " + "WHERE LOWER(o.firstName) LIKE LOWER(CONCAT('%', :namePart, '%')) " + "OR LOWER(o.lastName) LIKE LOWER(CONCAT('%', :namePart, '%'))") Page findByNameContaining(@Param("namePart") String namePart, Pageable pageable);