Spring MVC @PathVariable注解


下面用代碼來演示@PathVariable傳參方式

1 @RequestMapping("/user/{id}")
2 public String test(@PathVariable("id") Integer id){
3     System.out.println(id);
4     return "hello";
5 }

  在@RequestMapping中請求路徑,將需要傳遞的參數用{}括起來。通過@PathVariable("參數名稱")來獲取url中的參數值。要求@PathVariable中參數名稱必須和url中參數名稱一致

 

  例如:訪問  /user/1          ------------  對應id=1

        /user/2           ------------  對應id=2


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM