springmvc RequestMapping注解


1.  RequestMapping注解,源碼如下圖:

 

1.1 RequestMapping的作用介紹

@RequestMapping注解的主要作用是國際表示請求路徑與方法的映射關系,如下圖案列

上面案列的@RequestMapping注解的value是/hello在sayhello()方法上,表示用戶請求http://localhost:8085/hello的時候,該請求醬油sayHello()方法攔截處理.

 

1.2  @RequestMapping作用位置

該注解可以作用在方法和類上.

作用在類上:第一季的訪問目錄.

作用在方法上:第二季的訪問目錄.如下圖所示:

此時的請求地址則改變成了 http://localhost:8085/hello/say

 

1.3  @RequestMapping的屬性

path  value  method params headers等屬性

其中path和value的屬性用法是一樣的,如下圖所示:

method方法可以約束提交的方式 加了method = RequestMethod.POST 則只能用post方式提交 加了method = RequestMethod.get,則只能用get方法提交

params指定限制請求參數的條件

 

headers 發送的請求中必須包含的請求頭

 


免責聲明!

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



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