1. Mapping requests
role: Use requestmapping to specify that the processor can handle those requests
Place: Classes and Methods all in front .
@requestMapping
class definition : provides preliminary request mapping information relative to the Web app's root directory .
method definition : provides further subdivision mapping information relative to the URL at the class definition . If the class definition is not marked
@requestMapping, the URL at the method is relative to the Web app's root directory
2. Mapping parameters and Mapping headers
@RequestMapping (value= "Testparamsandhandler",params={"username", "age!=10"})
<!--map header file only as @RequestMapping (value= "Testhandler",headers={"accept-language= zh-cn,zh;q=0.8 "})
Simple expressions can be used @requestMapping mapping parameters and headers
1. params! =5 indicates that the request parameter cannot be equal to 5
2.! =params indicates that the request parameter cannot contain this parameter
3. params={"username", "age!=10"} request parameter contains multiple parameters
3. Sample Code
Controller
1 @Controller2 Public classSpringmvctest {3 4 /**5 * Configure @requestmapping Map Request Parameters6 * value is: Testparamsandhandler7 * Params parameter: Contains username, age!=108 */9@RequestMapping (value= "Testparamsandhandler", params={"username", "age!=10"})Ten PublicString Testparamsandhandler () { OneSystem.out.println ("Testparamsandhandler"); A return"Success"; - } -@RequestMapping (value= "Testhandler", headers={"accept-language=zh-cn,zh;q=0.8"}) the PublicString Testhandler () { -System.out.println ("Testhandler"); - return"Success"; - } +}
Front-end files
<ahref= "HelloWorld">[Email protected] "only method mapping"</a></BR>
<ahref= "Helloworld/hello">[Email protected] "class + method Map"</a></BR>
<ahref= "testparamsandhandler?username&age=100">Test-paramsandhandler "a href=" testparamsandhandler?username&age=100 ""</a></BR>
SPRINGMVC using requestmapping mapping requests, mapping parameters, mapping headers