From 98ccc1e2e4db7ff92ef8ac378f75d56b2a94e2c1 Mon Sep 17 00:00:00 2001 From: Perumal Raj A Date: Wed, 5 Feb 2025 09:44:41 +0000 Subject: [PATCH] Updated PR based on feedback Signed-off-by: Perumal Raj A --- .../samples/petclinic/owner/OwnerController.java | 5 ----- .../samples/petclinic/owner/OwnerRepository.java | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) 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);