Kann ich mit Spring 3.0 eine optionale Pfadvariable haben?
Beispielsweise
@RequestMapping(value = "/json/{type}", method = RequestMethod.GET)
public @ResponseBody TestBean testAjax(
HttpServletRequest req,
@PathVariable String type,
@RequestParam("track") String track) {
return new TestBean();
}
Hier möchte /json/abcoder möchte ich /jsondie gleiche Methode aufrufen.
Eine offensichtliche Problemumgehung typeals Anforderungsparameter deklarieren :
@RequestMapping(value = "/json", method = RequestMethod.GET)
public @ResponseBody TestBean testAjax(
HttpServletRequest req,
@RequestParam(value = "type", required = false) String type,
@RequestParam("track") String track) {
return new TestBean();
}
und dann /json?type=abc&track=aaoder /json?track=rrwird funktionieren