RequestMapping的相關知識講解(補)

2021-07-31 17:01:30 字數 861 閱讀 7457

第乙個使用比較廣泛,也很重要;後面的兩個註解只做乙個介紹,了解即可。

1.requestparam註解

requestparam註解用來對映請求引數,有三個屬性值

* value值:請求引數名

* required:指定請求引數是否必須

* defaultvalue:指定請求引數的預設值

另外注意,盡量不要使用基本資料型別,而使用它們的包裝類,這樣在不指定defaultvalue屬性的情況下,引數的預設值是null而不會報錯

public string testrequestparam(@requestparam(value="username") string username,@requestparam(value="age",required=false,defaultvalue="0") int age)

testrequestparam
2.requestheader註解

public string testrequestheader(@requestheader(value="host") string host)

testrequestheader
3.cookievalue註解

cookievalue註解了解即可,作用是獲取當前請求的指定名稱的cookie值

public string testcookievalue(@cookievalue(value="jsessionid") string sessionid)

testcookievalue

RequestMapping註解的用法

package com.springmvc.helloworld 1 import org.springframework.stereotype.controller import controller public class helloworld 上面 在類定義處指定對映為 example 在h...

RequestMapping的URL匹配過程

2 表示匹配任意乙個字元,可以放在任意位置,任意數量 示例 1 getuserbyurl1 2 getuserbyurl1 responsebody responseentitygetuserbyurl1 3 表示匹配任意數量的字元,包含0個 示例 1 getuserbyurl2 此時中間至少乙個值...

RequestMapping的簡單理解

controller public class itemcontroller 一般為首頁 public string showindex 只要下面haha刪除對應位置自定義名稱一致就行,隨便命名 param page return public string showpage pathvariabl...