mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 20:35:49 +00:00
Enhance_owner_search_functionality_1.0
Signed-off-by: Perumal Raj A <perumalraj024@gmail.com>
This commit is contained in:
parent
6148ddd967
commit
94d6335022
3 changed files with 15 additions and 7 deletions
|
@ -98,7 +98,7 @@ class OwnerController {
|
|||
}
|
||||
|
||||
// find owners by last name
|
||||
Page<Owner> ownersResults = findPaginatedForOwnersLastName(page, owner.getLastName());
|
||||
Page<Owner> ownersResults = findPaginatedForOwnersName(page, owner.getLastName());
|
||||
if (ownersResults.isEmpty()) {
|
||||
// no owners found
|
||||
result.rejectValue("lastName", "notFound", "not found");
|
||||
|
@ -124,10 +124,15 @@ class OwnerController {
|
|||
return "owners/ownersList";
|
||||
}
|
||||
|
||||
private Page<Owner> findPaginatedForOwnersLastName(int page, String lastname) {
|
||||
// private Page<Owner> findPaginatedForOwnersLastName(int page, String lastname) {
|
||||
// int pageSize = 5;
|
||||
// Pageable pageable = PageRequest.of(page - 1, pageSize);
|
||||
// return owners.findByLastNameStartingWith(lastname, pageable);
|
||||
// }
|
||||
private Page<Owner> findPaginatedForOwnersName(int page, String lastname) {
|
||||
int pageSize = 5;
|
||||
Pageable pageable = PageRequest.of(page - 1, pageSize);
|
||||
return owners.findByLastNameStartingWith(lastname, pageable);
|
||||
return owners.findByNameContaining(lastname, pageable);
|
||||
}
|
||||
|
||||
@GetMapping("/owners/{ownerId}/edit")
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.springframework.data.domain.Page;
|
|||
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;
|
||||
|
||||
/**
|
||||
|
@ -53,7 +54,10 @@ 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);
|
||||
// Page<Owner> 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<Owner> findByNameContaining(@Param("namePart") String namePart, Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieve an {@link Owner} from the data store by id.
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
Loading…
Reference in a new issue