ABSTRACTHANDLERMAPPENT는 핸드 레이핑 인터페이스로 지정된 Gethandler를 구현합니다
1. 서브 클래스 구현에 gethandlerinternal 템플릿 방법을 제공하십시오
2. 핸들러를 얻지 못하면 기본 불이행 란들러가 사용됩니다.
3. 핸들러가 문자열 유형 인 경우 컨텍스트에서 인스턴스를 가져옵니다.
4. gethandlerexecutionchain을 통해 핸들러를 캡슐화하고 인터셉터를 추가하십시오.
// ABSTRACTHANDLERMPAPP/*** 주어진 요청에 대한 핸들러를 찾아, 기본값* 핸들러로 돌아 가면 특정 핸들러가 찾을 수없는 경우 핸들러로 돌아갑니다. gethandlerinternal (request); if (handler == null) {handler = getDefaulthandler ();} if (handler == null) {return null;} // bean 이름 또는 해결 된 핸들러? if (string의 핸들러 인스턴스) {string handlername = (문자열) handler; handler = letapplicationcontext (getApplicationContext (). gethandlerexecutionchain (handler, request);} // AbstracthandLermpapp/*** 적용 가능한 인터셉터를 포함하여 주어진 핸들러에 대한 HandlereXecutionChain을 구축합니다.* <p> 기본 구현은 주어진 핸들러를 가진 표준 핸드 레드 넥션 체인을 구축합니다. URL. 서브 클래스는 인터셉터 목록을 확장/재 배열하기 위해 이것을 무시할 수 있습니다.* <p> <b> 참고 : </b> 통과 된 핸들러 객체는 원시 핸들러 또는 사전 구축* handlerexecutionchain 일 수 있습니다. 이 방법은 새로운 핸들 레스 신호 체인을 구축하거나 기존 체인을 확장하는 두 가지 사례를 명시 적으로 처리해야합니다.* <p> 간단히 인터셉터를 추가하려면 {@code super.gethandlexecutionchain}*을 호출하는 것을 고려하십시오. null})* @param 요청 현재 http 요청* @return handlerexecutionchain (honexecutionchain ({@code null})* @see #getAdaptedInterceptors ()*/protected handlerexecutionchain gethandlerexecutionchain (객체 핸들러, httpservletrequest 요청) {handler execution chain chain = handlerexecutionchain) 핸들러 : New HandlerexecutionChain (handler); chain.addinterceptors (getAdAptedInterceptors ()); 문자열 lookuppath = urlpathHelper.getLookUpPathForquest (요청); for (MappedInterceptor MappedInterceptor : MappedInterceptors) {if (MappedInterceptor.matches (LookupPath, Pathmatcher)) {chain.AddGintercepor.GetInterceptor (interceptor) 체인;} 다음으로 Abstracturlhandlermpapp에 의해 구현 된 gethandlerinternal을 살펴보십시오.
// AbstractUrlHandlerMpapping/*** 주어진 요청의 URL 경로에 대한 핸들러를 찾아보십시오.* @param 요청 현재 http 요청* @return htler instance 또는 {@code null}을 찾은 경우*/ @overrideprotected 오브젝트 GethandlerInternal (httpervletRequest 요청) 예외 {// get url upuppute = get url getring htring gets gethandlerinternal (httpervletrequest request). getUrlPathHelper (). getLookUpPathForRequest (요청); // handlerObject handler = lookuphandler (XookupPhandler, 요청); if (handler == null) {// 핸들러와 일치하지 않으면 기본값을 찾아야합니다. // path_within_handler_mapping_attribute를 노출시키기 위해. (rawhandler instance of string) {String handlername = (string) rawhandler; rawhandler = getApplicationContext (). getBean (handlername);} // 예약 된 검증 핸들러 템플릿 메소드는 validateHandler (rawHandler, request)를 사용하지 않습니다. null);}} if (handler! = null && logger.isdebugenabled ()) { "mapping [" + Xookuppath + "]에" + handler);} else if (handler == null && logger.istraceEnabled ()) {handler mapping for [ " + upup +")); handler;} // acpractUrlHandlerMpapp/*** 주어진 URL 경로에 대한 핸들러 인스턴스를 찾아보십시오.* <p>는 직접 일치를 지원합니다. 예를 들어 등록 된 "/테스트"매치 "/테스트",* 및 다양한 개미 스타일 패턴 일치, 예를 들어 등록 된 "/t*"매치* 둘 다 "/테스트"및 "/팀". 자세한 내용은 AntpathMatcher 클래스를 참조하십시오.* <p> 가장 정확한 패턴을 찾으십시오. 가장 정확한 패턴을 찾으십시오. 가장 정확한 패턴은* 가장 긴 경로 패턴으로 정의됩니다.* @param urlpath url Bean이* @param 요청 현재 http 요청에 매핑됩니다 (매핑 내에서 경로를 노출시키기 위해)* @code null} 또는 @code null}* @code null}* @code null}. org.springframework.util.antpathmatcher*/protected object lookuphandler (String urlpath, httpservletrequest 요청) 예외 {// direct match? 직접 검색 handlerObject handler = this.handlermap.get (urlpath); if (handler! = null) {// bean 이름 또는 해결 된 핸들러? if (handler instanceof string) {String handlername = (String) handler; handler = getApplicationContext (). getbean (handlername); 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; null; comparator <string> patterncomparator = getPathMatcher (getPathMatcher); if (! matchingpatterns.isempty ()) {collections.sort (matchingpatterns, pattern comparator); if (logger.isdebugenabled ()) {logger.debug ( "" + urlpath + "]의 일치 패턴 [" + urlpath + "]는" + matchingpatterns) // 가장 낮은 우선 순위가 가장 낮습니다. matchingpatterns.get ();} if (bestpatternmatch! = null) {handler = this.handlermap.get (bestpatternmatch); // bean name 또는 resolved handler? if (handler instanceof string) {string) handler = handler = handler = getApplicationContxt (). pathWithInMapping = getPathMatcher (). ExtractPathWithInPattern (BestPatternMatch, urlPath); // 여러 '최고의 패턴'이있을 수 있습니다. 모든 whiplatevariables = uritemplatevariables = new LinkedHashMap <String, ()에 대해 올바른 URI 템플릿 변수 //가 있는지 확인하십시오. for (string matchingpattern : matchingpatterns) {if (patterncomparator.compare (bestpatternmatch, matchingpattern) ==) {map <string, string> vars = getPathMatcher (). extraguritemplatevariablebles (matchingpattern, urlpath); map <string, string> decodedvars = geturlhelper (repuctorlhelper). vars); uritemplatevariables.putall (decodedvars);}} if (logger.isdebugenabled ()) {logger.debug ( "uri 템플릿 변수 [" " + urlpath +"]는 " + uritemplatevaribles); uritemplatevariables);} // 핸들러가 없음 ... return null;} 핸들러를 검증하도록 설계되었으며 서브 클래스를 포함하여 아무것도 수행되지 않습니다.
/*** 주어진 핸들러를 현재 요청에 대해 검증합니다.* <p> 기본 구현이 비어 있습니다. 예를 들어 URL 매핑에서 표현 된 특정 전제 조건을 시행하기 위해 하위 클래스에서 재정의 할 수 있습니다.* @param handler http 요청* @throws 예외*/protected validateHandler (객체 핸들러, httpservletrequest 요청) {} 핸들러를 HandlereXecutionChain으로 캡슐화하고 PathExpositingHandlerInterceptor 및 uritemplateVariaBleShandlerinterceptor 인터셉터를 추가하십시오.
/*** 주어진 원시 핸들러에 대한 핸들러 객체를 작성하고 실제* 핸들러, {@link #path_within_handler_mapping_attribute} 및 handler를 실행하기 전에* {@link #uri_template_variables_attribles}를 노출시키는 실제* 핸들러를 노출시킵니다.* <p> default a (default a ^ @link handlereocain). 경로 속성 및 URI 템플릿 변수* @param rawhandler handler를 실행하기 전에 노출을 노출시키는 경로를 노출시키기위한 원시 핸들러* @param uritemplatevariables uri 템플릿 변수는 {@code null}을 찾을 수 있다면*/retputebhinder (객체 핸들러 객체*/propected buildhered)가 될 수 있습니다. BestMatchingPattern, String PathWithInMapping, Map <String, String> uritemplateVariables) {HandlereXecutionChain Chain = New HandlerExecutionChain (RawHandler); chain.addinterceptor (새로운 PathExplessedHandlerInterceptor (BestMatchingPattern, PathWithInMapping)); if (! collectionUtils.isempty (uritemplatevariables)) {chain.addinterceptor (new uritemplatevariaBariaBariaBareShandlerInterceptor (uritemplateVaribles));}}.위의 내용은 귀하에게 소개 된 Handlermapping -AbstracturlHandlerMpapping Series 요청 배포의 SpringMVC 소스 코드 해석에 대한 관련 지식입니다. 나는 그것이 모두에게 도움이되기를 바랍니다!