If you rely on the 'Accept' header you can have:
Code:
@RequestMapping(value ="/{parentName}/{childName}", method=RequestMethod.GET)
public String doGet(Model model,
@PathVariable("parentName") String parentName,
@PathVariable("childName") String childName) {
DomainObject o = callSomeService.getObject(childName);
model.addAttribute("object", o);
return "redirect:/" + parentName";
}
@RequestMapping(value ="/*/{childName}", method=RequestMethod.GET, produces="application/xml")
public DomainObject doGetAsXml@PathVariable("childName") String childName) {
return callSomeService.getObject(childName);
}
The doGetAsXml method doesn't specify a view name because I assume you have MarshallingView as a default view in the ContentNegotiatingViewResolver. Not the only way to do it but to me it is a little more clear at the cost of some brevity.