@RequestMapping testing Various access methods

Source: Internet
Author: User

Here to visit the page in the Web-inf directory, this does not know that there is no similar to struts2 like the wildcard character can access different action, different method, different pages, the user is very cool, some words to tell, and I have a problem is configured with the following configuration, But not access to static resources, hope to answer!! -----Access Path: http://localhost:8080/Springmvc3/images/4.jpg


Well, the others did not say, look as follows:

Configuring the View resolver



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 ")//can also be written as @requestmapping ("/test.do ") can not be written, because in Web. XML is configured with *.dopublic class TestController {@RequestMapping ( params= "Method=adduser") public String addUser (user user) {System.out.println ("dddddddddd"); return "Success";} @RequestMapping (value= "/test0")//default is Get mode public String test0 () {System.out.println ("Access path: Test/test0.do"); return " Success ";} @RequestMapping (value= "/test1", method=requestmethod.post) public String test1 (String sex) {System.out.println (sex); SYSTEM.OUT.PRINTLN ("Access path is: Test/test1.do, and is get way ___" +sex); return "Success";} @RequestMapping (value= "/test2", method=requestmethod.get,params= "Param=test2") public String test2 () { SYSTEM.OUT.PRINTLN ("Access path is: Test/test1.do?param=test2, and"Get"); return "Success";} Rest-style parameter @requestmapping (value= "/test3/{name}") public string test3 (@PathVariable string name) {// The name of the formal parameter and the receiving parameter are consistent System.out.println (name); SYSTEM.OUT.PRINTLN ("Access path: Test/test3/zhangsan.do"); System.out.println ("Look at the access path here, the ' Zhangsan ' parameter value is passed directly to the name parameter name in @requestmapping (value=\"/test3/{name}\ "), Optionally named parameter name, "); return" Success ";} @RequestMapping (value= "/test5/{name}") public string Test5 (@PathVariable ("name") string rename) {// The name of the formal parameter and the receiving parameter are inconsistent System.out.println (rename); SYSTEM.OUT.PRINTLN ("Access path: Test/test5/zhangsan.do"); System.out.println ("Look at the access path here, the ' Zhangsan ' parameter value is passed directly to the name parameter name in @requestmapping (value=\"/test5/{name}\ "), Optionally named parameter name, "+" and then the name of the @pathvariable (\ "Name\") is in accordance with that name above, and then bind this name to the parameter rename "); return" Success ";} @RequestMapping (value= "/test4/{sex}/{sno}")//Here I write @requestmapping (value= "Test4/{sex}/{sno}") also can drop public String Test4 (@PathVariable ("sex") string sex, @PathVariable ("Sno") string sno) {System.out.println (sex); SYSTEM.ERR.PRINTLN (SNO); SYSTEM.OUT.PRINTLN ("Access path: TEST/test4/male/10506.do "); return" Success ";} Supports regular @requestmapping (value= "/test6/{textualpart:[a-z-]+}.{ numericpart:[\\d]+} ") public string Test6 (@PathVariable string textualpart, @PathVariable string numericpart) { System.out.println (Textualpart);//Output sometxtSystem.out.println (Numericpart);//Output 123system.out.println (" Access path: Test/test6/sometxt.123.do "); return" Success ";} Access to the Web-inf under the views file in the different directories of the page, here is access to the user directory, do not know what other good way not @requestmapping (value= "/test7") public String test7 () { SYSTEM.OUT.PRINTLN ("Access path: Test/test7.do"); return "User/success";}}

@RequestMapping test various access methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.