Springmvc Source code Interpretation-requestmapping Annotation implementation Interpretation-Requestmappinginfo

Source: Internet
Author: User

When using @requestmapping annotations, the configured information is finally set to Requestmappinginfo.

Requestmappinginfo encapsulated the patternsrequestcondition,requestmethodsrequestcondition,paramsrequestcondition and so on, so I do not work, All the work is entrusted to the specific condition processing.

First look at the package of Requestcondition bar, the previous article will be relatively thin, not clear what each class is exactly what to do, you can move here <springmvc source Interpretation-requestmapping annotation implementation Interpretation- Requestcondition System >

1  PackageOrg.springframework.web.servlet.mvc.method;2  Public Final classRequestmappinginfoImplementsRequestcondition<requestmappinginfo> {3 4     Private Finalpatternsrequestcondition patternscondition;5 6     Private Finalrequestmethodsrequestcondition methodscondition;7 8     Private Finalparamsrequestcondition paramscondition;9 Ten     Private Finalheadersrequestcondition headerscondition; One  A     Private Finalconsumesrequestcondition consumescondition; -  -     Private Finalproducesrequestcondition producescondition; the  -     Private FinalRequestconditionholder Customconditionholder; -}

Initialization is nothing nice, just look at the implementation of the interface.

Seemingly combine also no material, is commissioned separately

1     /**2 * combines ' this ' request mapping info (i.e. the current instance) with another request mapping info instance.3 * <p>example:combine type-and method-level request mappings.4      * @returna new request mapping info instance; never {@codenull}5      */6      PublicRequestmappinginfo Combine (requestmappinginfo other) {7Patternsrequestcondition patterns = This. Patternscondition.combine (other.patternscondition);8Requestmethodsrequestcondition methods = This. Methodscondition.combine (other.methodscondition);9Paramsrequestcondition params = This. Paramscondition.combine (other.paramscondition);TenHeadersrequestcondition headers = This. Headerscondition.combine (other.headerscondition); OneConsumesrequestcondition consumes = This. Consumescondition.combine (other.consumescondition); AProducesrequestcondition produces = This. Producescondition.combine (other.producescondition); -Requestconditionholder custom = This. Customconditionholder.combine (Other.customconditionholder); -  the         return NewRequestmappinginfo (patterns, methods, params, headers, consumes, produces, custom.getcondition ()); -}

Getmatchingcondition only reflects the possibility of performance-based consumption considerations, the comparison of Patternsrequestcondition and Requestconditionholder to the back of the separate processing.

1     /**2 * Checks If all conditions in this request mapping info match the provided request and returns3 * A potentially new request mapping info with conditions tailored to the current request.4 * <p>for Example The returned instance may contain the subset of the URL patterns this match to5 * The current request, sorted and best matching patterns on top.6      * @returna new instance in case all conditions match;@codeNULL} otherwise7      */8      Publicrequestmappinginfo getmatchingcondition (httpservletrequest request) {9Requestmethodsrequestcondition methods =methodscondition.getmatchingcondition (request);TenParamsrequestcondition params =paramscondition.getmatchingcondition (request); OneHeadersrequestcondition headers =headerscondition.getmatchingcondition (request); AConsumesrequestcondition consumes =consumescondition.getmatchingcondition (request); -Producesrequestcondition produces =producescondition.getmatchingcondition (request); -  the         if(Methods = =NULL|| params = =NULL|| headers = =NULL|| consumes = =NULL|| produces = =NULL) { -             return NULL; -         } -  +Patternsrequestcondition patterns =patternscondition.getmatchingcondition (request); -         if(Patterns = =NULL) { +             return NULL; A         } at  -Requestconditionholder custom =customconditionholder.getmatchingcondition (request); -         if(Custom = =NULL) { -             return NULL; -         } -  in         return NewRequestmappinginfo (patterns, methods, params, headers, consumes, produces, custom.getcondition ()); -}

CompareTo is the priority of a different requestcondition.

1     /**2 * Compares "this" info (i.e. the current instance) and another info in the context of a request.3 * <p>note:it is assumed both instances has been obtained via4      * {@link#getMatchingCondition (HttpServletRequest)} to ensure they has conditions with5 * Content relevant to current request.6      */7      Public intCompareTo (Requestmappinginfo Other, httpservletrequest request) {8         intresult =Patternscondition.compareto (Other.getpatternscondition (), request);9         if(Result! = 0) {Ten             returnresult; One         } Aresult =Paramscondition.compareto (Other.getparamscondition (), request); -         if(Result! = 0) { -             returnresult; the         } -result =Headerscondition.compareto (Other.getheaderscondition (), request); -         if(Result! = 0) { -             returnresult; +         } -result =Consumescondition.compareto (Other.getconsumescondition (), request); +         if(Result! = 0) { A             returnresult; at         } -result =Producescondition.compareto (Other.getproducescondition (), request); -         if(Result! = 0) { -             returnresult; -         } -result =Methodscondition.compareto (Other.getmethodscondition (), request); in         if(Result! = 0) { -             returnresult; to         } +result =Customconditionholder.compareto (Other.customconditionholder, request); -         if(Result! = 0) { the             returnresult; *         } $         return0;Panax Notoginseng}

The equals,hashcode,tostring don't look.

Springmvc Source code Interpretation-requestmapping Annotation implementation interpretation-Requestmappinginfo

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.