SpringMVC中@RequestParam注解作用


1.不使用@RequestParam
  請求參數名必須和形參名稱一樣


2.使用@RequestParam
    請求參數名必須和@RequestParam value屬性值一樣
    請求參數名不必和形參名稱一樣
 
    3個屬性的使用
    value
    required:請求參數是否必須傳入
    defaultValue:請求參數的默認值,如果請求參數沒有傳入,則將默認值與形參進行綁定

例子:

1       //method:限制請求方法
2       @RequestMapping(value="/getItems.action",method = { RequestMethod.POST,RequestMethod.GET })    
3       public String getItems(Model model,@RequestParam(value="id",required=false,defaultValue = "1") Integer itemsId) {
4             ItemsCustom itemsCustom = this.itemsService.getItems(itemsId);
5             model.addAttribute("itemsCustom", itemsCustom);
6             return "items/editItems";     //返回的是邏輯視圖(前綴+邏輯視圖+后綴=物理視圖路徑) 
7       }

 


免責聲明!

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



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