mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 12:25:50 +00:00
moved from Model to Map so we do not use a Spring-specific class
This commit is contained in:
parent
bd9446e091
commit
2b0d07bbba
4 changed files with 20 additions and 14 deletions
|
@ -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";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue