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 @@
package org.springframework.samples.petclinic.web;
import java.util.Collection;
import java.util.Map;
import javax.validation.Valid;
......@@ -58,9 +59,9 @@ public class OwnerController {
}
@RequestMapping(value = "/owners/new", method = RequestMethod.GET)
public String initCreationForm(Model model) {
public String initCreationForm(Map<String, Object> model) {
Owner owner = new Owner();
model.addAttribute(owner);
model.put("owner", owner);
return "owners/createOrUpdateOwnerForm";
}
......@@ -76,13 +77,13 @@ public class OwnerController {
}
@RequestMapping(value = "/owners/find", method = RequestMethod.GET)
public String initFindForm(Model model) {
model.addAttribute("owner", new Owner());
public String initFindForm(Map<String, Object> model) {
model.put("owner", new Owner());
return "owners/findOwners";
}
@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
if (owner.getLastName() == null) {
......@@ -98,7 +99,7 @@ public class OwnerController {
}
if (results.size() > 1) {
// multiple owners found
model.addAttribute("selections", results);
model.put("selections", results);
return "owners/ownersList";
} else {
// 1 owner found
......
......@@ -16,6 +16,7 @@
package org.springframework.samples.petclinic.web;
import java.util.Collection;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.model.Owner;
......@@ -62,11 +63,11 @@ public class PetController {
}
@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);
Pet pet = new Pet();
owner.addPet(pet);
model.addAttribute("pet", pet);
model.put("pet", pet);
return "pets/createOrUpdatePetForm";
}
......@@ -83,9 +84,9 @@ public class PetController {
}
@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);
model.addAttribute("pet", pet);
model.put("pet", pet);
return "pets/createOrUpdatePetForm";
}
......
......@@ -15,6 +15,8 @@
*/
package org.springframework.samples.petclinic.web;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.model.Vets;
import org.springframework.samples.petclinic.service.ClinicService;
......@@ -40,12 +42,12 @@ public class VetController {
}
@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
// so it is simpler for Object-Xml mapping
Vets vets = new Vets();
vets.getVetList().addAll(this.clinicService.findVets());
model.addAttribute("vets", vets);
model.put("vets", vets);
return "vets/vetList";
}
......
......@@ -15,6 +15,8 @@
*/
package org.springframework.samples.petclinic.web;
import java.util.Map;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -57,11 +59,11 @@ public class VisitController {
}
@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);
Visit visit = new Visit();
pet.addVisit(visit);
model.addAttribute("visit", visit);
model.put("visit", visit);
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