В Spring 3.0 я могу иметь необязательную переменную пути?
Например
@RequestMapping(value = "/json/{type}", method = RequestMethod.GET)
public @ResponseBody TestBean testAjax(
HttpServletRequest req,
@PathVariable String type,
@RequestParam("track") String track) {
return new TestBean();
}
Здесь я хотел бы /json/abcили /jsonвызвать тот же метод.
Один очевидный обходной путь объявляется typeкак параметр запроса:
@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();
}
а потом /json?type=abc&track=aaили /json?track=rrбудет работать