Với Spring 3.0, tôi có thể có một biến đường dẫn tùy chọn không?
Ví dụ
@RequestMapping(value = "/json/{type}", method = RequestMethod.GET)
public @ResponseBody TestBean testAjax(
HttpServletRequest req,
@PathVariable String type,
@RequestParam("track") String track) {
return new TestBean();
}
Ở đây tôi muốn /json/abchoặc /jsongọi phương thức tương tự.
Một cách giải quyết rõ ràng typelà một tham số yêu cầu:
@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();
}
và sau đó /json?type=abc&track=aahoặc /json?track=rrsẽ làm việc