Skip to content

Commit c647207

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

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
package com.example.springpetclinic.controllers;
22

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

8+
@RequestMapping("/vets")
69
@Controller
710
public class VetController {
8-
@RequestMapping({"/vets", "/vets/index", "/vets/index.html"})
9-
public String listVets() {
11+
12+
private final VetService vetService;
13+
14+
VetController(VetService vetService) {
15+
this.vetService = vetService;
16+
}
17+
18+
@RequestMapping({"/", "/index", "/index.html"})
19+
public String listVets(Model model) {
20+
model.addAttribute("vets", vetService.findAll());
21+
1022
return "vets/index";
1123
}
1224
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>List of Owners</title>
66
</head>
77
<body>
8-
<!--/*@thymesVar id="owner" type="guru.springframework.sfgpetclinic.model.Owner"*/-->
8+
<!--/*@thymesVar id="owner" type="com.example.springpetclinic.model.Owner"*/-->
99
<h2 th:text="'List of Owners'">Owners List</h2>
1010

1111
<table class="table table-striped">

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
<title>List of Vets</title>
66
</head>
77
<body>
8-
<h1 th:text="'List of Vets'">List of Vets...</h1>
8+
<!--/*@thymesVar id="vet" type="com.example.springpetclinic.model.Vet"*/-->
9+
<h2>Veterinarians</h2>
10+
11+
<table class="table table-striped" id="vets">
12+
<thead>
13+
<tr>
14+
<th>Name</th>
15+
<th>Specialties</th>
16+
</tr>
17+
</thead>
18+
<tbody>
19+
<tr th:each="vet : ${vets}">
20+
<td th:text="${vet?.id}">1</td>
21+
<td th:text="${vet?.firstName}">Joe</td>
22+
<td th:text="${vet?.lastName}">Buck</td>
23+
</tr>
24+
</tbody>
25+
</table>
926
</body>
1027
</html>

0 commit comments

Comments
 (0)