SpringMVC -- @RequestMapping用法

來源:互聯網
上載者:User

標籤:spring mvc

繼續http://blog.csdn.net/gaopeng0071/article/details/47447811章節,

瞭解@RequestMapping更多其他用法,查看@RequestMapping參數

用法如下

value:

In a Servlet environment: the path mapping URIs (e.g. “/myPath.do”). Ant-style path patterns are also supported (e.g. “/myPath/*.do”). At the method level, relative paths (e.g. “edit.do”) are supported within the primary mapping expressed at the type level.

  • 支援”/myPath.do”用法
  • 支援ANT風格的URL,如”/myPath/*.do”
    /user/aaa/createUser、/user/bbb/createUser 等 URL
    /user/**/createUser: 匹配 –
    /user/createUser、/user/aaa/bbb/createUser 等 URL
    /user/createUser??: 匹配 –
    /user/createUseraa、/user/createUserbb 等 URL

代碼

    @RequestMapping(value = "/*/sayHello")    public String sayHello() {        System.out.println("hello world!!!");        return "success";    }
<a href="springMVC/aaa/sayHello.do">Test HelloWorld</a>
method:

The HTTP request methods to map to, narrowing the primary mapping: GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE.

主要使用GET、POST兩種請求方式。

代碼

    @RequestMapping(value = "/testRequestMethod", method = RequestMethod.POST)    public String testRequestMethod() {        System.out.println("testRequestMethod");        return "success";    }
    <form action="springMVC/testRequestMethod.do" method="post">        <input type="submit" value="testRequestMethod" />    </form>
params:

Same format for any environment: a sequence of “myParam=myValue” style expressions, with a request only mapped if each such parameter is found to have the given value. Expressions can be negated by using the “!=” operator, as in “myParam!=myValue”. “myParam” style expressions are also supported, with such parameters having to be present in the request (allowed to have any value). Finally, “!myParam” style expressions indicate that the specified parameter is not supposed to be present in the request.

  • !param1: 表示請求不能包含名為 param1 的請求參數
  • param1 != value1: 表示請求包含名為 param1 的請求參數,但其值不能為 value1
  • {“param1=value1”, “param2”}: 請求必須包含名為 param1 和param2的兩個請求參數,且 param1 參數的值必須為 value1

代碼

    @RequestMapping(value = "/testParam", params = "userId=‘userName‘ ")    public String testParam() {        System.out.println("params userId is not null");        return "success";    }
    <a href="springMVC/testParam.do?userId=userName ">testParam</a>

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

SpringMVC -- @RequestMapping用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.