ด้วย 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จะทำงาน