Skip to content
Snippets Groups Projects
Commit 2b0d07bb authored by Mic's avatar Mic
Browse files

moved from Model to Map so we do not use a Spring-specific class

parent bd9446e0
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package org.springframework.samples.petclinic.web; package org.springframework.samples.petclinic.web;
import java.util.Collection; import java.util.Collection;
import java.util.Map;
import javax.validation.Valid; import javax.validation.Valid;
...@@ -58,9 +59,9 @@ public class OwnerController { ...@@ -58,9 +59,9 @@ public class OwnerController {
} }
@RequestMapping(value = "/owners/new", method = RequestMethod.GET) @RequestMapping(value = "/owners/new", method = RequestMethod.GET)
public String initCreationForm(Model model) { public String initCreationForm(Map<String, Object> model) {
Owner owner = new Owner(); Owner owner = new Owner();
model.addAttribute(owner); model.put("owner", owner);
return "owners/createOrUpdateOwnerForm"; return "owners/createOrUpdateOwnerForm";
} }
...@@ -76,13 +77,13 @@ public class OwnerController { ...@@ -76,13 +77,13 @@ public class OwnerController {
} }
@RequestMapping(value = "/owners/find", method = RequestMethod.GET) @RequestMapping(value = "/owners/find", method = RequestMethod.GET)
public String initFindForm(Model model) { public String initFindForm(Map<String, Object> model) {
model.addAttribute("owner", new Owner()); model.put("owner", new Owner());
return "owners/findOwners"; return "owners/findOwners";
} }
@RequestMapping(value = "/owners", method = RequestMethod.GET) @RequestMapping(value = "/owners", method = RequestMethod.GET)
public String processFindForm(Owner owner, BindingResult result, Model model) { public String processFindForm(Owner owner, BindingResult result, Map<String, Object> model) {
// allow parameterless GET request for /owners to return all records // allow parameterless GET request for /owners to return all records
if (owner.getLastName() == null) { if (owner.getLastName() == null) {
...@@ -98,7 +99,7 @@ public class OwnerController { ...@@ -98,7 +99,7 @@ public class OwnerController {
} }
if (results.size() > 1) { if (results.size() > 1) {
// multiple owners found // multiple owners found
model.addAttribute("selections", results); model.put("selections", results);
return "owners/ownersList"; return "owners/ownersList";
} else { } else {
// 1 owner found // 1 owner found
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package org.springframework.samples.petclinic.web; package org.springframework.samples.petclinic.web;
import java.util.Collection; import java.util.Collection;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.model.Owner; import org.springframework.samples.petclinic.model.Owner;
...@@ -62,11 +63,11 @@ public class PetController { ...@@ -62,11 +63,11 @@ public class PetController {
} }
@RequestMapping(value = "/owners/{ownerId}/pets/new", method = RequestMethod.GET) @RequestMapping(value = "/owners/{ownerId}/pets/new", method = RequestMethod.GET)
public String initCreationForm(@PathVariable("ownerId") int ownerId, Model model) { public String initCreationForm(@PathVariable("ownerId") int ownerId, Map<String, Object> model) {
Owner owner = this.clinicService.findOwnerById(ownerId); Owner owner = this.clinicService.findOwnerById(ownerId);
Pet pet = new Pet(); Pet pet = new Pet();
owner.addPet(pet); owner.addPet(pet);
model.addAttribute("pet", pet); model.put("pet", pet);
return "pets/createOrUpdatePetForm"; return "pets/createOrUpdatePetForm";
} }
...@@ -83,9 +84,9 @@ public class PetController { ...@@ -83,9 +84,9 @@ public class PetController {
} }
@RequestMapping(value = "/owners/*/pets/{petId}/edit", method = RequestMethod.GET) @RequestMapping(value = "/owners/*/pets/{petId}/edit", method = RequestMethod.GET)
public String initUpdateForm(@PathVariable("petId") int petId, Model model) { public String initUpdateForm(@PathVariable("petId") int petId, Map<String, Object> model) {
Pet pet = this.clinicService.findPetById(petId); Pet pet = this.clinicService.findPetById(petId);
model.addAttribute("pet", pet); model.put("pet", pet);
return "pets/createOrUpdatePetForm"; return "pets/createOrUpdatePetForm";
} }
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
*/ */
package org.springframework.samples.petclinic.web; package org.springframework.samples.petclinic.web;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.model.Vets; import org.springframework.samples.petclinic.model.Vets;
import org.springframework.samples.petclinic.service.ClinicService; import org.springframework.samples.petclinic.service.ClinicService;
...@@ -40,12 +42,12 @@ public class VetController { ...@@ -40,12 +42,12 @@ public class VetController {
} }
@RequestMapping("/vets") @RequestMapping("/vets")
public String showVetList(Model model) { public String showVetList(Map<String, Object> model) {
// Here we are returning an object of type 'Vets' rather than a collection of Vet objects // Here we are returning an object of type 'Vets' rather than a collection of Vet objects
// so it is simpler for Object-Xml mapping // so it is simpler for Object-Xml mapping
Vets vets = new Vets(); Vets vets = new Vets();
vets.getVetList().addAll(this.clinicService.findVets()); vets.getVetList().addAll(this.clinicService.findVets());
model.addAttribute("vets", vets); model.put("vets", vets);
return "vets/vetList"; return "vets/vetList";
} }
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
*/ */
package org.springframework.samples.petclinic.web; package org.springframework.samples.petclinic.web;
import java.util.Map;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -57,11 +59,11 @@ public class VisitController { ...@@ -57,11 +59,11 @@ public class VisitController {
} }
@RequestMapping(value = "/owners/*/pets/{petId}/visits/new", method = RequestMethod.GET) @RequestMapping(value = "/owners/*/pets/{petId}/visits/new", method = RequestMethod.GET)
public String initNewVisitForm(@PathVariable("petId") int petId, Model model) { public String initNewVisitForm(@PathVariable("petId") int petId, Map<String, Object> model) {
Pet pet = this.clinicService.findPetById(petId); Pet pet = this.clinicService.findPetById(petId);
Visit visit = new Visit(); Visit visit = new Visit();
pet.addVisit(visit); pet.addVisit(visit);
model.addAttribute("visit", visit); model.put("visit", visit);
return "pets/createOrUpdateVisitForm"; return "pets/createOrUpdateVisitForm";
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment