This commit is contained in:
Perumal Raj A 2025-03-27 17:41:50 +01:00 committed by GitHub
commit 5b74887026
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 5 deletions

View file

@ -110,9 +110,9 @@ class OwnerController {
owner = ownersResults.iterator().next();
return "redirect:/owners/" + owner.getId();
}
// multiple owners found
return addPaginationModel(page, model, ownersResults);
}
private String addPaginationModel(int page, Model model, Page<Owner> paginated) {

View file

@ -24,6 +24,9 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
/**
* Repository class for <code>Owner</code> domain objects All method names are compliant
* with Spring Data naming conventions so this interface can easily be extended for Spring
@ -52,7 +55,9 @@ public interface OwnerRepository extends JpaRepository<Owner, Integer> {
* @return a Collection of matching {@link Owner}s (or an empty Collection if none
* found)
*/
Page<Owner> findByLastNameStartingWith(String lastName, Pageable pageable);
@Query("SELECT o FROM Owner o WHERE LOWER(CONCAT(o.firstName, ' ', o.lastName)) LIKE LOWER(CONCAT('%', :namePart, '%'))")
Page<Owner> findByLastNameStartingWith(@Param("namePart") String namePart, Pageable pageable);
/**
* Retrieve an {@link Owner} from the data store by id.

View file

@ -9,7 +9,7 @@
class="form-horizontal" id="search-owner-form">
<div class="form-group">
<div class="control-group" id="lastNameGroup">
<label class="col-sm-2 control-label">Last name </label>
<label class="col-sm-2 control-label">Search by Name</label>
<div class="col-sm-10">
<input class="form-control" th:field="*{lastName}" size="30"
maxlength="80" /> <span class="help-inline"><div
@ -21,8 +21,7 @@
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Find
Owner</button>
<button type="submit" class="btn btn-primary">Search</button>
</div>
</div>