mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-06 16:15:50 +00:00
Add methods to support pet name search
This commit is contained in:
parent
6328d2c9dc
commit
d7ece043ac
1 changed files with 25 additions and 1 deletions
|
@ -54,6 +54,30 @@ public interface OwnerRepository extends JpaRepository<Owner, Integer> {
|
|||
*/
|
||||
Page<Owner> findByLastNameStartingWith(String lastName, Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieve {@link Owner}s from the data store whose pets' names contain the given name.
|
||||
* @param petName Value to search for in pet names (supports fuzzy search)
|
||||
* @param pageable pagination information
|
||||
* @return a Collection of matching {@link Owner}s (or an empty Collection if none
|
||||
* found)
|
||||
*/
|
||||
@Query("SELECT DISTINCT owner FROM Owner owner JOIN owner.pets pet WHERE pet.name LIKE %:petName%")
|
||||
Page<Owner> findByPetNameContaining(@org.springframework.data.repository.query.Param("petName") String petName, Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieve {@link Owner}s from the data store by combining last name and pet name search.
|
||||
* @param lastName Value to search for in last names
|
||||
* @param petName Value to search for in pet names
|
||||
* @param pageable pagination information
|
||||
* @return a Collection of matching {@link Owner}s (or an empty Collection if none
|
||||
* found)
|
||||
*/
|
||||
@Query("SELECT DISTINCT owner FROM Owner owner JOIN owner.pets pet WHERE owner.lastName LIKE %:lastName% AND pet.name LIKE %:petName%")
|
||||
Page<Owner> findByLastNameAndPetName(
|
||||
@org.springframework.data.repository.query.Param("lastName") String lastName,
|
||||
@org.springframework.data.repository.query.Param("petName") String petName,
|
||||
Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieve an {@link Owner} from the data store by id.
|
||||
* <p>
|
||||
|
|
Loading…
Reference in a new issue