Configuring the View resolver
11 PackageCom.tgb.controller; 2233ImportOrg.springframework.stereotype.Controller; 44Importorg.springframework.web.bind.annotation.PathVariable; 55Importorg.springframework.web.bind.annotation.RequestMapping; 66ImportOrg.springframework.web.bind.annotation.RequestMethod; 7788ImportCom.tgb.entity.User; 99Ten10@Controller OneOne @RequestMapping ("/test") A12//This can also be written as @requestmapping ("/test.do") or not, because the *.do is configured in Web. XML -13 Public classTestController { -14 the@RequestMapping (params= "Method=adduser") -16 PublicString addUser (user user) { -System.out.println ("dddddddddd"); -18return"Success"; +19 } -20 +@RequestMapping (value= "/test0")//The default is Get mode A22 PublicString test0 () { atSYSTEM.OUT.PRINTLN ("Access path: Test/test0.do"); -24return"Success"; -25 } -26 -@RequestMapping (value= "/test1", method=requestmethod.post) -28 Publicstring test1 (String sex) { in29System.out.println (Sex); -SYSTEM.OUT.PRINTLN ("Access path is: Test/test1.do, and is get way ___" +sex); to31return"Success"; +32 } -33 the@RequestMapping (value= "/test2", method=requestmethod.get,params= "Param=test2") *35 PublicString test2 () { $SYSTEM.OUT.PRINTLN ("Access path: Test/test1.do?param=test2, and get Mode"); Panax Notoginseng37return"Success"; -38 } the39 +40//Rest-style parameters A@RequestMapping (value= "/test3/{name}") the42 PublicString Test3 (@PathVariable string name) {//the name of the formal parameter and the receive parameter match +43System.out.println (name); -SYSTEM.OUT.PRINTLN ("Access path: Test/test3/zhangsan.do")); $System.out.println ("Look at the access path here, directly will ' Zhangsan ' This parameter value is passed to the @requestmapping (value=\"/test3/{name}\ ") in the name parameter name, can be arbitrarily named Parameter name, "); $46return"Success"; -47 } -48 the@RequestMapping (value= "/test5/{name}") -50 PublicString Test5 (@PathVariable ("name") string rename) {//the name of the parameter and receive parameters are inconsistentWuyi51System.out.println (rename); theSYSTEM.OUT.PRINTLN ("Access path: Test/test5/zhangsan.do")); -System.out.println ("Look at the access path here, directly will ' Zhangsan ' This parameter value is passed to the @requestmapping (value=\"/test5/{name}\ ") in the name parameter name, can be arbitrarily named Parameter name, "+ Wu54 "Then the name of the @pathvariable (\" Name\ ") in the back is consistent with that name above, then bind this name to the parameter rename"); -55return"Success"; About56 } $57 -@RequestMapping (value= "/test4/{sex}/{sno}") -59//Here I write @requestmapping (value= "Test4/{sex}/{sno}") also can drop -60 PublicString Test4 (@PathVariable ("sex") string sex, @PathVariable ("Sno") String Sno) { A61System.out.println (Sex); +62System.err.println (SNO); theSYSTEM.OUT.PRINTLN ("Access path: Test/test4/male/10506.do"); -64return"Success"; $65 } the66 the67//Support Regular the@RequestMapping (value= "/test6/{textualpart:[a-z-]+}.{ numericpart:[\\d]+} ") the69 Publicstring Test6 (@PathVariable string textualpart, @PathVariable string numericpart) { -System.out.println (Textualpart);//Output Sometxt inSystem.out.println (Numericpart);//Output 123 theSYSTEM.OUT.PRINTLN ("Access path: Test/test6/sometxt.123.do"); the73return"Success"; About74 } the75 the76//access to the Web-inf under the views file in the different directories of the page, which is accessed in the user directory, do not know what other good ways not the@RequestMapping (value= "/test7")) +78 PublicString test7 () { -SYSTEM.OUT.PRINTLN ("Access path: Test/test7.do"); the80return"User/success"; Bayi81 } the82 the83}
@RequestMapping testing Various access methods