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
|
@ -112,7 +112,7 @@ public class OwnerController {
|
|||
else {
|
||||
this.ownerRepository.save(owner);
|
||||
status.setComplete();
|
||||
return "redirect:/owners/" + owner.getId();
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public class PetController {
|
|||
else {
|
||||
this.clinicService.savePet(pet);
|
||||
status.setComplete();
|
||||
return "redirect:/owners/" + pet.getOwner().getId();
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ public class PetController {
|
|||
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) {
|
||||
// we're not using @Valid annotation here because it is easier to define such validation rule in Java
|
||||
new PetValidator().validate(pet, result);
|
||||
|
@ -90,7 +90,7 @@ public class PetController {
|
|||
else {
|
||||
this.clinicService.savePet(pet);
|
||||
status.setComplete();
|
||||
return "redirect:/owners/" + pet.getOwner().getId();
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public class VisitController {
|
|||
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) {
|
||||
if (result.hasErrors()) {
|
||||
return "pets/createOrUpdateVisitForm";
|
||||
|
@ -61,7 +61,7 @@ public class VisitController {
|
|||
else {
|
||||
this.clinicService.saveVisit(visit);
|
||||
status.setComplete();
|
||||
return "redirect:/owners/" + visit.getPet().getOwner().getId();
|
||||
return "redirect:/owners/{ownerId}";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,23 +19,19 @@
|
|||
- property of the vets view bean, setting it to 'application/vnd.springsource.samples.petclinic+xml'.
|
||||
-->
|
||||
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
|
||||
<property name="contentNegotiationManager">
|
||||
<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="contentNegotiationManager" ref="cnManager"/>
|
||||
<property name="order" value="0"/>
|
||||
</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).
|
||||
- It has the order property set to 2, which means that this will
|
||||
|
|
Loading…
Reference in a new issue