This commit is contained in:
Namaskruti Pal 2025-07-07 09:03:08 -06:00 committed by GitHub
commit 6304de8cfc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 0 deletions

View file

@ -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
}
}

View file

@ -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();
}

View 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>