1
2 package org.springframework.samples.petclinic.web;
3
4 import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.samples.petclinic.Clinic;
6 import org.springframework.samples.petclinic.Vets;
7 import org.springframework.stereotype.Controller;
8 import org.springframework.ui.ModelMap;
9 import org.springframework.web.bind.annotation.PathVariable;
10 import org.springframework.web.bind.annotation.RequestMapping;
11 import org.springframework.web.bind.annotation.RequestMethod;
12 import org.springframework.web.servlet.ModelAndView;
13
14
15
16
17
18
19
20
21
22
23 @Controller
24 public class ClinicController {
25
26 private final Clinic clinic;
27
28
29 @Autowired
30 public ClinicController(Clinic clinic) {
31 this.clinic = clinic;
32 }
33
34
35
36
37
38
39
40
41 @RequestMapping("/")
42 public String welcomeHandler() {
43 return "welcome";
44 }
45
46
47
48
49
50
51
52
53
54
55
56 @RequestMapping("/vets")
57 public ModelMap vetsHandler() {
58 Vets vets = new Vets();
59 vets.getVetList().addAll(this.clinic.getVets());
60 return new ModelMap(vets);
61 }
62
63
64
65
66
67
68
69 @RequestMapping("/owners/{ownerId}")
70 public ModelAndView ownerHandler(@PathVariable("ownerId") int ownerId) {
71 ModelAndView mav = new ModelAndView("owners/show");
72 mav.addObject(this.clinic.loadOwner(ownerId));
73 return mav;
74 }
75
76
77
78
79
80
81
82 @RequestMapping(value="/owners/*/pets/{petId}/visits", method=RequestMethod.GET)
83 public ModelAndView visitsHandler(@PathVariable int petId) {
84 ModelAndView mav = new ModelAndView("visits");
85 mav.addObject("visits", this.clinic.loadPet(petId).getVisits());
86 return mav;
87 }
88
89 }