SPRINGMVC using requestmapping mapping requests, mapping parameters, mapping headers

Source: Internet
Author: User

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

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.