springMVC的@RequestMapping的參數和用法

來源:互聯網
上載者:User

標籤:

 

RequestMapping註解裡麵包含的參數

 

value: 控制器名字也是url的映射

params:url中的參數,可以是多個

method: http請求的動作. get  post  put delete...

headers : 要求標頭參數

@PathVariable :映射 URL 綁定佔位  ( 映射URL路徑裡面的變數)

 

@Controller//映射 控制器類@RequestMapping("/hellotest")public class Hello2 {    public final static String DISPATCHER  ="show";        @RequestMapping("/test")    public String testUrl(){                System.out.println("testUrl=http://localhost:8080/springMVC/hellotest/test");        return DISPATCHER;    }     /**      * get動作請求的測試      * @return      */    @RequestMapping(method=RequestMethod.GET,value="/testMethodGet")    public String testMethodGet(){        System.out.println("get..............");        return DISPATCHER;    }      /**     * post動作請求的測試     * @return     */    @RequestMapping(method=RequestMethod.POST,value="/testMethodPost")    public String testMethodPost(){        System.out.println("post..............");        return DISPATCHER;    }    /**     * 測試url中帶參數(未測試要求標頭資訊)     * @return     */    @RequestMapping(value="/testHeadersAndParams",            params={"username","sex!=1","password=123"},            method=RequestMethod.GET)    public String testHeadersAndParams(){        //url http://localhost:8080/springMVC/hellotest/testHeadersAndParams?username=10&password=123&sex=2        System.out.println("testHeadersAndParams");        return DISPATCHER;    }    //PathVariable 映射 URL 綁定佔位  ( 映射URL路徑裡面的變數)    @RequestMapping(value="/testPathVariable/{id}",method=RequestMethod.GET)    public String testPathVariable(@PathVariable("id") Integer id){        System.out.println("testPathVariable  id:"+id);        //http://localhost:8080/springMVC/hellotest/testPathVariable/5        return DISPATCHER;    }    @RequestMapping(value="/testPathVariable2/{name}",method=RequestMethod.GET)    public String testPathVariable2(@PathVariable("name") String name){        System.out.println("testPathVariable  name :"+name);        // http://localhost:8080/springMVC/hellotest/testPathVariable2/str      return DISPATCHER;    }    @RequestMapping()    public String test(){         return DISPATCHER;    }}

 

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.