Abstracthandlermappingは、ハンドラーラッピングインターフェイスによって指定されたゲサンドラーを実装します
1.サブクラスの実装にgethandlerinternalテンプレートメソッドを提供します
2。ハンドラーが取得されない場合、デフォルトのDefaulthandlerが使用されます。
3.ハンドラーが文字列タイプの場合、コンテキストからインスタンスを取得します
4。gethandlerexecutionchainを介してハンドラーをカプセル化し、インターセプターを追加します
// abstracthandlermapping/***指定された要求のハンドラーを検索し、具体的なものが見つからない場合はデフォルトに戻る*ハンドラーに戻ります。 gethandlerininternal(request); if(handler == null){handler = getDefaultherler();} if(handler == null){return null;} // bean nameまたはresolved handler?if(handler instance of string){string handlername =(string)handler = getapplicationcontext( gethandlerexecutionChain(ハンドラー、リクエスト);} // abstacthandlermapping/***該当するインターセプターを含む特定のハンドラーのハンドレレックス執行チェーンを構築します。 URL。サブクラスは、インターセプターのリストを拡張/再配置するためにこれをオーバーライドする場合があります。* <p> <b>注:</b>渡されたハンドラーオブジェクトは、生のハンドラーまたは事前に構築された* Handlerexecutionchainである場合があります。この方法は、これらの2つのケースを明示的に処理する必要があります。*新しいHandLerexecutionChainの構築または既存のチェーンの拡張のいずれかです。* <p>単にインターセプターを追加するために、{@code super.gethandlerexecutionchain}を呼び出して{@link handlerexecutionchain#adterceptor}を呼び出すことを検討してください。 null})* @param request Current http request* @@return the handlerexecutionchain(never {@code null})* @see #getAdaptedInterceptors()*/保護されたHandLerexecutionChain GethandlerexecutionChain(オブジェクトハンドラー、httpservletRequestRequeSteain = Handlerexecunechain =(handlerexecutututice chean =) HandLerexecutionChain)ハンドラー:新しいHandLerexecutionChain(ハンドラー); Chain.AddInterceptors(getAdaptedInterceptors()); string lookuppath = urlpathhelper.getlookuppath(request); {Chain.AdddInterceptor(mappedInterceptor.getInterceptor();}} return Chain;}次に、abstracturllhandlermappingによって実装されたgethandlerinternalをご覧ください
// abstracturllhandlermapping/***指定された要求のURLパスのハンドラーを検索します。 geturlpathhelper()。getlookuppathforRequest(request); // handlerobject handler = lookuphandler(lookuppath、request); if(handler == null){//ハンドラーに一致しない場合、デフォルトを見つける必要がある場合、パス_within_handler_handler_attributeが必要ですPath_within_handler_mapping_attribute for it.object rawhandler = null; if( "/".equals(lookuppath)){rawhandler = getroothandler();} if(rawhandler = null = getdefaulthler();} if(rawhandler! (文字列のrawhandlerインスタンス){string handlername =(string)rawhandler; rawhandler = getApplicationContext()。getBean(Handlername);} //予約された検証ハンドラーテンプレートメソッドは検証ハンドラーを使用しません(Rawhandler、リクエスト); lookuppath、null);}} if(handler!= null && logger.isdebugenabled()){logger.debug( "mapping [" + lookuppath + "] to" + handler);} else if(handler == null && logger.istraceEnabled()) "]");} return handler;} // abstracturllhandlermapping/***指定されたURLパスのハンドラーインスタンスを検索します。* <p>直接一致をサポートします。詳細については、Antpathmatcherクラスを参照してください。* <p>最も正確なパターンを探します。最も正確なパターンは*最長のパスパターンと定義されています。 @see org.springframework.util.antpathmatcher*/保護されたオブジェクトLookuphandler(string urlpath、httpservletrequest request)スロー例外{//ダイレクトマッチ? HandlerObject Handler = this.handlermap.get(urlpath); if(handler!= null){// bean name or resolved handler?if(handler instanceof string){string handlername =(string)handler; handler = getApplicationContext()。 urlpath、urlpath、null);} //パターンマッチ?式を介した一致は、Antpathmatcherを介して実装されます。特定の分析は、リスト<string> matchingpatterns = new ArrayList <String>(); for(string registeredpattern:this.handlermap.keyset()){if(getPathMatcher()。match(registeredpattern、urlpath)){matchingpatterns.add(RegisteredPattern);}} string bestpatternmatch = null; comparator <string> patternpatrator = getpathmatcher(); if(!matchingpatterns.isempty()){collections.sort(matchingpatterns、patternComparator); if(logger.isdebugenabled()){logger.debug( "要求のマッチングパターン[" + urlpath + "] are" + matchingpatterns);} matchingpatterns.get();} if(bestpatternmatch!= null){handler = this.handlermap.get(bestpatternmatch); // bean name or resolvedハンドラー? PathWithInMapping = getPathMatcher()。extractPathwithinpattern(bestpatternmatch、urlpath); //複数の「最高のパターン」があるかもしれません。 for(string matchingpattern:matchingpatterns){if(patterncomparator.compare(bestpatternmatch、matchingpattern)==){map <string> vars = getPathMatcher()。 geturlpathhelper()。decodepathvariables(request、vars); uritemplatevariables.putall(decodedvars);}} if(logger.isdebugenabled()){logger.debug( "uri template variables for require for request [" + urlpath + "; buildpathexposededler(ハンドラー、bestpatternmatch、pathwithinmapping、uritemplatevariables);} //ハンドラーは見つかりません... return null;}ハンドラーを検証するように設計されていますが、サブクラスなど、何も行われません。
/***現在の要求に対して指定されたハンドラーを検証します。* <p>デフォルトの実装は空です。サブクラスでオーバーライドすることができます。たとえば、URLマッピングで表現された特定の前提条件を実施するために。
ハンドラーをHandLerexecutionChainとしてカプセル化し、PathExpositingHandlerInterceptorおよびUritemplateVariableshandlerInterceptorインターセプターを追加します。
/***与えられた生のハンドラーのハンドラーオブジェクトを構築し、実際の*ハンドラー、{@link #path_within_handler_mapping_attribute}、および* @link #uri_template_variables_attribute}を公開します。パス属性とURIテンプレート変数を公開* @param rawhandler生のハンドラーは、ハンドラーを実行する前にパスを露出するパスを露出するための生のハンドラー* @param uritemplate変数を実行する前に公開します。 string bestmatchingpattern、string path withinmapping、map <string、string> uritemplatevariables){handlerexecutionchain chain = new handlerexecutionchain(rawhandler); Chain.AddDINTERCEPTOR(new PathExposedEdhandLerCeptor(BestMatchingPattern、PathWithinMapping))上記のコンテンツは、HandlermappingのSpringMVCソースコード解釈に関する関連知識です-Abstracturllhandlermappingシリーズリクエスト配布が紹介されています。私はそれが誰にでも役立つことを願っています!