能不能限制 getPet 方法 {petId} 只能的 a和b
@Controller
@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET, produces="application/json")
@ResponseBody
public Pet getPet(@PathVariable String petId, Model model) {
// implementation omitted
}
可以使用正则进行约束,在变量名后面加上:
即可, 如下:
@Controller
@RequestMapping(value = "/pets/{petId:a|b}", method = RequestMethod.GET, produces="application/json")
@ResponseBody
public Pet getPet(@PathVariable String petId, Model model) {
// implementation omitted
}
没懂你的意思