Dengan Spring 3.0, dapatkah saya memiliki variabel jalur opsional?
Sebagai contoh
@RequestMapping(value = "/json/{type}", method = RequestMethod.GET)
public @ResponseBody TestBean testAjax(
HttpServletRequest req,
@PathVariable String type,
@RequestParam("track") String track) {
return new TestBean();
}
Di sini saya ingin /json/abcatau /jsonmemanggil metode yang sama.
Satu solusi nyata menyatakan typesebagai parameter permintaan:
@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();
}
dan kemudian /json?type=abc&track=aaatau /json?track=rrakan bekerja