Skip to content

Commit 42bfc9c

Browse files
committed
List all Owners on Owners Index Page. Closes #25
Signed-off-by: Ankur Paul <[email protected]>
1 parent fb3c465 commit 42bfc9c

File tree

2 files changed

+31
-2
lines changed
  • Track 2_JAVA and SQL/SpringFramework/SpringPetClinic/pet-clinic-web/src/main

2 files changed

+31
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
package com.example.springpetclinic.controllers;
22

3+
import com.example.springpetclinic.services.OwnerService;
34
import org.springframework.stereotype.Controller;
5+
import org.springframework.ui.Model;
46
import org.springframework.web.bind.annotation.RequestMapping;
57

68
@RequestMapping("/owners")
79
@Controller
810
public class OwnerController {
11+
12+
private final OwnerService ownerService;
13+
14+
public OwnerController(OwnerService ownerService) {
15+
this.ownerService = ownerService;
16+
}
17+
918
@RequestMapping({"/", "/index", "/index.html"})
10-
public String listOwners() {
19+
public String listOwners(Model model) {
20+
model.addAttribute("owners", ownerService.findAll());
21+
1122
return "owners/index.html";
1223
}
1324
}

Track 2_JAVA and SQL/SpringFramework/SpringPetClinic/pet-clinic-web/src/main/resources/templates/owners/index.html

+19-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@
55
<title>List of Owners</title>
66
</head>
77
<body>
8-
<h1 th:text="'List of Owners'">List of Owners...</h1>
8+
<!--/*@thymesVar id="owner" type="guru.springframework.sfgpetclinic.model.Owner"*/-->
9+
<h2 th:text="'List of Owners'">Owners List</h2>
10+
11+
<table class="table table-striped">
12+
<thead>
13+
<tr>
14+
<th style="width: 150px;">Id</th>
15+
<th style="width: 150px;">First Name</th>
16+
<th style="width: 150px;">Last Name</th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<tr th:each="owner : ${owners}">
21+
<td th:text="${owner?.id}">1</td>
22+
<td th:text="${owner?.firstName}">Joe</td>
23+
<td th:text="${owner?.lastName}">Buck</td>
24+
</tr>
25+
</tbody>
26+
</table>
927
</body>
1028
</html>

0 commit comments

Comments
 (0)