我对 spring 框架有点陌生,@PathVariable在我的应用程序中使用时我感到困惑。要求是categoryId从url pattern. 这是我写的jsp:
<a href="cat/1">Categories</a>
当它被点击时,我想从 url 中收集 categoryId,这就是我在 Controller 中写的:
@RequestMapping(value ="/cat/{categoryId}", method = RequestMethod.GET)
public String getCategory(@PathVariable("categoryId") Category categoryId, ModelMap model) {
System.out.println("Path variable : " + categoryId);
return "category";
}