mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-16 04:45:49 +00:00
Merge b7932cead7
into 30aab0ae76
This commit is contained in:
commit
6304de8cfc
3 changed files with 20 additions and 0 deletions
|
@ -169,5 +169,11 @@ class OwnerController {
|
|||
mav.addObject(owner);
|
||||
return mav;
|
||||
}
|
||||
@GetMapping("/owners/count")
|
||||
public String countOwners(Model model) {
|
||||
int count = owners.countOwners();
|
||||
model.addAttribute("count", count);
|
||||
return "owners/ownerCount"; // we'll create this HTML view next
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,4 +62,7 @@ public interface OwnerRepository extends JpaRepository<Owner, Integer> {
|
|||
*/
|
||||
Optional<Owner> findById(@Nonnull Integer id);
|
||||
|
||||
@Query("SELECT COUNT(o) FROM Owner o")
|
||||
int countOwners();
|
||||
|
||||
}
|
||||
|
|
11
src/main/resources/templates/owners/ownerCount.html
Normal file
11
src/main/resources/templates/owners/ownerCount.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title>Owner Count</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Total number of owners: <span th:text="${count}">0</span></h2>
|
||||
<a href="/owners">Back to Owners List</a>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in a new issue