@RequestMapping測試各種訪問方式

來源:互聯網
上載者:User

標籤:

這裡訪問WEB-INF目錄下的頁面,這個還不知道有沒有類似struts2那樣的萬用字元來可以訪問不同的action,不同的method,不同 的頁面,使用者則很爽,有的話求告知,而且我還有一個問題就是配置了如下的配置,但卻訪問不到靜態資源,望解答!!-----訪問路徑:http://localhost:8080/Springmvc3/images/4.jpg


好了,其他不說了,看如下:

配置視圖解析器



 

package com.tgb.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import com.tgb.entity.User;@Controller@RequestMapping("/test")//這裡也可以寫成@RequestMapping("/test.do")也可以不寫,因為在web.xml中配置了*.dopublic class TestController {@RequestMapping(params="method=addUser")public String addUser(User user){System.out.println("dddddddddd");return "success";}@RequestMapping(value="/test0")//預設為get方式public String test0(){System.out.println("訪問路徑:test/test0.do");return "success";}@RequestMapping(value="/test1",method=RequestMethod.POST)public String test1(String sex){System.out.println(sex);System.out.println("訪問路徑為:test/test1.do,而且是get方式______"+sex);return "success";}@RequestMapping(value="/test2",method=RequestMethod.GET,params="param=test2")public String test2(){System.out.println("訪問路徑為:test/test1.do?param=test2,而且是get方式");return "success";}//REST風格的參數@RequestMapping(value="/test3/{name}")public String test3(@PathVariable String name){//形參和接收參數的名稱一致System.out.println(name);System.out.println("訪問路徑為:test/test3/zhangsan.do");System.out.println("看這裡的訪問路徑,直接就將‘zhangsan’這個參數值就傳遞給了@RequestMapping(value=\"/test3/{name}\")中的name參數名,可隨意具名引數名稱,");return "success";}@RequestMapping(value="/test5/{name}")public String test5(@PathVariable("name")String rename){//形參和接收參數的名稱不一致System.out.println(rename);System.out.println("訪問路徑為:test/test5/zhangsan.do");System.out.println("看這裡的訪問路徑,直接就將‘zhangsan’這個參數值就傳遞給了@RequestMapping(value=\"/test5/{name}\")中的name參數名,可隨意具名引數名稱," +"然後後面的@PathVariable(\"name\")中的name名稱要和上面的那個name保持一致,然後把此name綁定到形參rename");return "success";}@RequestMapping(value="/test4/{sex}/{sno}")//這裡我寫成@RequestMapping(value="test4/{sex}/{sno}")也是可以滴public String test4(@PathVariable("sex")String sex,@PathVariable("sno")String sno){System.out.println(sex);System.err.println(sno);System.out.println("訪問路徑:test/test4/male/10506.do");return "success";}//支援正則@RequestMapping(value="/test6/{textualPart:[a-z-]+}.{numericPart:[\\d]+}")public String test6(@PathVariable String textualPart,@PathVariable String numericPart){System.out.println(textualPart);//輸出sometxtSystem.out.println(numericPart);//輸出123System.out.println("訪問路徑:test/test6/sometxt.123.do");return "success";}//訪問WEB-INF下的views檔案中的不同目錄的頁面,這裡訪問的是user目錄下的,不知道其他有什麼好的辦法沒@RequestMapping(value="/test7")public String test7(){System.out.println("訪問路徑:test/test7.do");return "user/success";}}

@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.