在Spring 3.0中,我可以有一个可选的path变量吗?
例如
@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
将工作