mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-05-29 22:59:38 +00:00
Polish
Use ContentNegotiationManagerFactoryBean Use URI variables in redirect URLs
This commit is contained in:
parent
572ef6e2c4
commit
3e66379be1
5 changed files with 26 additions and 30 deletions
|
@ -22,7 +22,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JavaBean form controller that is used to handle <code>Owner</code>s .
|
* JavaBean form controller that is used to handle <code>Owner</code>s .
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Ken Krebs
|
* @author Ken Krebs
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
@ -63,7 +63,7 @@ public class OwnerController {
|
||||||
return "redirect:/owners/" + owner.getId();
|
return "redirect:/owners/" + owner.getId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/owners/find", method = RequestMethod.GET)
|
@RequestMapping(value = "/owners/find", method = RequestMethod.GET)
|
||||||
public String initFindForm(Model model) {
|
public String initFindForm(Model model) {
|
||||||
model.addAttribute("owner", new Owner());
|
model.addAttribute("owner", new Owner());
|
||||||
|
@ -96,7 +96,7 @@ public class OwnerController {
|
||||||
return "redirect:/owners/" + owner.getId();
|
return "redirect:/owners/" + owner.getId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value="/owners/{ownerId}/edit", method = RequestMethod.GET)
|
@RequestMapping(value="/owners/{ownerId}/edit", method = RequestMethod.GET)
|
||||||
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
||||||
Owner owner = this.ownerRepository.findById(ownerId);
|
Owner owner = this.ownerRepository.findById(ownerId);
|
||||||
|
@ -112,10 +112,10 @@ public class OwnerController {
|
||||||
else {
|
else {
|
||||||
this.ownerRepository.save(owner);
|
this.ownerRepository.save(owner);
|
||||||
status.setComplete();
|
status.setComplete();
|
||||||
return "redirect:/owners/" + owner.getId();
|
return "redirect:/owners/{ownerId}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom handler for displaying an owner.
|
* Custom handler for displaying an owner.
|
||||||
*
|
*
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.springframework.web.bind.support.SessionStatus;
|
||||||
/**
|
/**
|
||||||
* JavaBean form controller that is used to add a new <code>Pet</code> to the
|
* JavaBean form controller that is used to add a new <code>Pet</code> to the
|
||||||
* system.
|
* system.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Ken Krebs
|
* @author Ken Krebs
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
@ -35,7 +35,7 @@ public class PetController {
|
||||||
|
|
||||||
private final ClinicService clinicService;
|
private final ClinicService clinicService;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public PetController(ClinicService clinicService) {
|
public PetController(ClinicService clinicService) {
|
||||||
this.clinicService = clinicService;
|
this.clinicService = clinicService;
|
||||||
|
@ -69,10 +69,10 @@ public class PetController {
|
||||||
else {
|
else {
|
||||||
this.clinicService.savePet(pet);
|
this.clinicService.savePet(pet);
|
||||||
status.setComplete();
|
status.setComplete();
|
||||||
return "redirect:/owners/" + pet.getOwner().getId();
|
return "redirect:/owners/{ownerId}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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, Model model) {
|
||||||
Pet pet = this.clinicService.findPetById(petId);
|
Pet pet = this.clinicService.findPetById(petId);
|
||||||
|
@ -80,7 +80,7 @@ public class PetController {
|
||||||
return "pets/createOrUpdatePetForm";
|
return "pets/createOrUpdatePetForm";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value="/owners/*/pets/{petId}/edit", method = { RequestMethod.PUT, RequestMethod.POST })
|
@RequestMapping(value="/owners/{ownerId}/pets/{petId}/edit", method = { RequestMethod.PUT, RequestMethod.POST })
|
||||||
public String processUpdateForm(@ModelAttribute("pet") Pet pet, BindingResult result, SessionStatus status) {
|
public String processUpdateForm(@ModelAttribute("pet") Pet pet, BindingResult result, SessionStatus status) {
|
||||||
// we're not using @Valid annotation here because it is easier to define such validation rule in Java
|
// we're not using @Valid annotation here because it is easier to define such validation rule in Java
|
||||||
new PetValidator().validate(pet, result);
|
new PetValidator().validate(pet, result);
|
||||||
|
@ -90,7 +90,7 @@ public class PetController {
|
||||||
else {
|
else {
|
||||||
this.clinicService.savePet(pet);
|
this.clinicService.savePet(pet);
|
||||||
status.setComplete();
|
status.setComplete();
|
||||||
return "redirect:/owners/" + pet.getOwner().getId();
|
return "redirect:/owners/{ownerId}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import org.springframework.web.servlet.ModelAndView;
|
||||||
/**
|
/**
|
||||||
* JavaBean form controller that is used to add a new <code>Visit</code> to the
|
* JavaBean form controller that is used to add a new <code>Visit</code> to the
|
||||||
* system.
|
* system.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Ken Krebs
|
* @author Ken Krebs
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
@ -53,7 +53,7 @@ public class VisitController {
|
||||||
return "pets/createOrUpdateVisitForm";
|
return "pets/createOrUpdateVisitForm";
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value="/owners/*/pets/{petId}/visits/new", method = RequestMethod.POST)
|
@RequestMapping(value="/owners/{ownerId}/pets/{petId}/visits/new", method = RequestMethod.POST)
|
||||||
public String processNewVisitForm(@Valid Visit visit, BindingResult result, SessionStatus status) {
|
public String processNewVisitForm(@Valid Visit visit, BindingResult result, SessionStatus status) {
|
||||||
if (result.hasErrors()) {
|
if (result.hasErrors()) {
|
||||||
return "pets/createOrUpdateVisitForm";
|
return "pets/createOrUpdateVisitForm";
|
||||||
|
@ -61,10 +61,10 @@ public class VisitController {
|
||||||
else {
|
else {
|
||||||
this.clinicService.saveVisit(visit);
|
this.clinicService.saveVisit(visit);
|
||||||
status.setComplete();
|
status.setComplete();
|
||||||
return "redirect:/owners/" + visit.getPet().getOwner().getId();
|
return "redirect:/owners/{ownerId}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom handler for displaying an list of visits.
|
* Custom handler for displaying an list of visits.
|
||||||
*
|
*
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
-->
|
-->
|
||||||
<context:component-scan base-package="org.springframework.samples.petclinic.web, org.springframework.samples.petclinic.service"/>
|
<context:component-scan base-package="org.springframework.samples.petclinic.web, org.springframework.samples.petclinic.service"/>
|
||||||
|
|
||||||
<mvc:annotation-driven conversion-service="conversionService"/>
|
<mvc:annotation-driven conversion-service="conversionService" />
|
||||||
|
|
||||||
<!-- all resources inside folder src/main/webapp/resources are mapped so they can be refered to inside JSP files
|
<!-- all resources inside folder src/main/webapp/resources are mapped so they can be refered to inside JSP files
|
||||||
(see header.jsp for more details) -->
|
(see header.jsp for more details) -->
|
||||||
|
|
|
@ -19,23 +19,19 @@
|
||||||
- property of the vets view bean, setting it to 'application/vnd.springsource.samples.petclinic+xml'.
|
- property of the vets view bean, setting it to 'application/vnd.springsource.samples.petclinic+xml'.
|
||||||
-->
|
-->
|
||||||
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
|
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
|
||||||
<property name="contentNegotiationManager">
|
<property name="contentNegotiationManager" ref="cnManager"/>
|
||||||
<bean class="org.springframework.web.accept.ContentNegotiationManager">
|
|
||||||
<constructor-arg>
|
|
||||||
<bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
|
|
||||||
<constructor-arg>
|
|
||||||
<map>
|
|
||||||
<entry key="xml" value="application/vnd.springsource.samples.petclinic+xml"/>
|
|
||||||
<entry key="atom" value="#{visitList.contentType}"/>
|
|
||||||
</map>
|
|
||||||
</constructor-arg>
|
|
||||||
</bean>
|
|
||||||
</constructor-arg>
|
|
||||||
</bean>
|
|
||||||
</property>
|
|
||||||
<property name="order" value="0"/>
|
<property name="order" value="0"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="cnManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
|
||||||
|
<property name="mediaTypes">
|
||||||
|
<value>
|
||||||
|
xml=application/vnd.springsource.samples.petclinic+xml
|
||||||
|
atom=#{visitList.contentType}
|
||||||
|
</value>
|
||||||
|
</property>
|
||||||
|
</bean>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
- The BeanNameViewResolver is used to pick up the visits view name (below).
|
- The BeanNameViewResolver is used to pick up the visits view name (below).
|
||||||
- It has the order property set to 2, which means that this will
|
- It has the order property set to 2, which means that this will
|
||||||
|
|
Loading…
Reference in a new issue