[英]trouble in using @PathVariable in spring mvc based application
我對spring框架有點@PathVariable
在我的應用程序中使用@PathVariable
時感到困惑。 要求是從url pattern
訪問categoryId
。 這就是我用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";
}
所以搞砸了自己后得到了問題。 無論我在Category.java pojo類中使用String還是int類型變量,都無法將categoryId與pojo類對象綁定。 因此,最后我在Controller的getCategory()方法中將參數類型更改為String,並且可以正常工作。 仍然不知道為什么它不能與pojo類對象綁定。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.