这里继续续写上一章博客(111章博客):   
Spring MVC 源码深度剖析:   
 
 
 < packaging> </ packaging> < dependencies> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> < scope> </ scope> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> </ dependencies> <?xml version="1.0" encoding="UTF-8"?> 
< web-appxmlns = " http://xmlns.jcp.org/xml/ns/javaee" xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation= " http://xmlns.jcp.org/xml/ns/javaee
                             http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version = " 4.0" > < servlet> < servlet-name> </ servlet-name> < servlet-class> </ servlet-class> < init-param> < param-name> </ param-name> < param-value> </ param-value> </ init-param> < load-on-startup> </ load-on-startup> </ servlet> < servlet-mapping> < servlet-name> </ servlet-name> < url-pattern> </ url-pattern> </ servlet-mapping> </ web-app> < beansxmlns = " http://www.springframework.org/schema/beans" xmlns: mvc= " http://www.springframework.org/schema/mvc" xmlns: context= " http://www.springframework.org/schema/context" xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation= " http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context.xsd
         http://www.springframework.org/schema/mvc
         http://www.springframework.org/schema/mvc/spring-mvc.xsd" > < context: component-scanbase-package = " com" /> </ beans> package  com. service ; 
public  interface  Demo  { 
    void  fa ( String  name) ; 
} 
package  com. service. impl ; 
import  com. service.  Demo ; 
import  org. springframework. stereotype.  Service ; 
@Service 
public  class  DemoImpl  implements  Demo  { 
    @Override 
    public  void  fa ( String  name)  { 
        System . out. println ( "你好:" + name) ; 
    } 
} 
package  com. controller ; 
import  com. service.  Demo ; 
import  org. springframework. beans. factory. annotation.  Autowired ; 
import  org. springframework. stereotype.  Controller ; 
import  org. springframework. web. bind. annotation.  RequestMapping ; 
@Controller 
@RequestMapping ( "/demo" ) 
public  class  DemoController  { 
    @Autowired 
    private  Demo  dome; 
    @RequestMapping ( "/name" ) 
    public  void  fa ( String  name)  { 
        dome. fa ( name) ; 
    } 
} 
plugins { 
    id 'java' 
    id 'war' 
} 
group 'org.springframework' 
version '5.1.21.BUILD-SNAPSHOT' 
repositories { 
    mavenCentral ( ) 
} 
dependencies { 
    
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' 
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' 
    implementation 'org.springframework:spring-webmvc:5.1.5.RELEASE' 
    implementation 'javax.servlet:javax.servlet-api:3.1.0' 
    providedCompile 'javax.servlet.jsp:jsp-api:2.2' 
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8' 
    implementation 'com.fasterxml.jackson.core:jackson-core:2.9.8' 
    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.0' 
} 
test { 
    useJUnitPlatform ( ) 
} 
public  class  DispatcherServlet  extends  FrameworkServlet  { 
 
     protected  void  doService ( HttpServletRequest  request,  HttpServletResponse  response)  throws  Exception  { 
         
        this . logRequest ( request) ; 
         
        Map < String ,  Object > =  null ; 
        if  ( WebUtils . isIncludeRequest ( request) )  { 
            attributesSnapshot =  new  HashMap ( ) ; 
            Enumeration  attrNames =  request. getAttributeNames ( ) ; 
            label95: 
            while ( true )  { 
                String  attrName; 
                do  { 
                    if  ( ! attrNames. hasMoreElements ( ) )  { 
                        break  label95; 
                    } 
                    attrName =  ( String ) attrNames. nextElement ( ) ; 
                }  while ( ! this . cleanupAfterInclude &&  ! attrName. startsWith ( "org.springframework.web.servlet" ) ) ; 
                attributesSnapshot. put ( attrName,  request. getAttribute ( attrName) ) ; 
            } 
        } 
         
        request. setAttribute ( WEB_APPLICATION_CONTEXT_ATTRIBUTE ,  this . getWebApplicationContext ( ) ) ; 
        request. setAttribute ( LOCALE_RESOLVER_ATTRIBUTE ,  this . localeResolver) ; 
        request. setAttribute ( THEME_RESOLVER_ATTRIBUTE ,  this . themeResolver) ; 
        request. setAttribute ( THEME_SOURCE_ATTRIBUTE ,  this . getThemeSource ( ) ) ; 
         
        if  ( this . flashMapManager !=  null )  { 
            FlashMap  inputFlashMap =  this . flashMapManager. retrieveAndUpdate ( request,  response) ; 
            if  ( inputFlashMap !=  null )  { 
                request. setAttribute ( INPUT_FLASH_MAP_ATTRIBUTE ,  Collections . unmodifiableMap ( inputFlashMap) ) ; 
            } 
            request. setAttribute ( OUTPUT_FLASH_MAP_ATTRIBUTE ,  new  FlashMap ( ) ) ; 
            request. setAttribute ( FLASH_MAP_MANAGER_ATTRIBUTE ,  this . flashMapManager) ; 
        } 
        try  { 
            
            this . doDispatch ( request,  response) ; 
        }  finally  { 
            
            if  ( ! WebAsyncUtils . getAsyncManager ( request) . isConcurrentHandlingStarted ( )  &&  attributesSnapshot !=  null )  { 
                this . restoreAttributesAfterInclude ( request,  attributesSnapshot) ; 
            } 
        } 
    } 
     
    protected  void  doDispatch ( HttpServletRequest  request,  HttpServletResponse  response)  throws  Exception  { 
        
        HttpServletRequest  processedRequest =  request; 
        
        HandlerExecutionChain  mappedHandler =  null ; 
        
        boolean  multipartRequestParsed =  false ; 
        
        WebAsyncManager  asyncManager =  WebAsyncUtils . getAsyncManager ( request) ; 
        try  { 
            try  { 
                
                ModelAndView  mv =  null ; 
                 
                Object  dispatchException =  null ; 
                try  { 
                    
                    processedRequest =  this . checkMultipart ( request) ; 
                    multipartRequestParsed =  processedRequest !=  request; 
                    
                    mappedHandler =  this . getHandler ( processedRequest) ; 
                     
                    if  ( mappedHandler ==  null )  { 
                        this . noHandlerFound ( processedRequest,  response) ; 
                        return ; 
                    } 
                    
                    HandlerAdapter  ha =  this . getHandlerAdapter ( mappedHandler. getHandler ( ) ) ; 
                    
                    String  method =  request. getMethod ( ) ; 
                    boolean  isGet =  "GET" . equals ( method) ; 
                    
                    
                    if  ( isGet ||  "HEAD" . equals ( method) )  { 
                        
                        long  lastModified =  ha. getLastModified ( request,  mappedHandler. getHandler ( ) ) ; 
                        
                        
                        if  ( ( new  ServletWebRequest ( request,  response) ) . checkNotModified ( lastModified)  &&  isGet)  { 
                            return ; 
                        } 
                    } 
                    
                    
                    
                    if  ( ! mappedHandler. applyPreHandle ( processedRequest,  response) )  { 
                       
                        
                        return ; 
                    } 
                    
                    
                    mv =  ha. handle ( processedRequest,  response,  mappedHandler. getHandler ( ) ) ; 
                    
                    if  ( asyncManager. isConcurrentHandlingStarted ( ) )  { 
                        return ; 
                    } 
                    
                    this . applyDefaultViewName ( processedRequest,  mv) ; 
                    
                    mappedHandler. applyPostHandle ( processedRequest,  response,  mv) ; 
                }  catch  ( Exception  var20)  { 
                    dispatchException =  var20; 
                }  catch  ( Throwable  var21)  { 
                    dispatchException =  new  NestedServletException ( "Handler dispatch failed" ,  var21) ; 
                } 
                
                this . processDispatchResult ( processedRequest,  response,  mappedHandler,  mv,  ( Exception ) dispatchException) ; 
            }  catch  ( Exception  var22)  { 
                
                this . triggerAfterCompletion ( processedRequest,  response,  mappedHandler,  var22) ; 
            }  catch  ( Throwable  var23)  { 
                this . triggerAfterCompletion ( processedRequest,  response,  mappedHandler,  new  NestedServletException ( "Handler processing failed" ,  var23) ) ; 
            } 
        }  finally  { 
            
            if  ( asyncManager. isConcurrentHandlingStarted ( ) )  { 
                if  ( mappedHandler !=  null )  { 
                    mappedHandler. applyAfterConcurrentHandlingStarted ( processedRequest,  response) ; 
                } 
            }  else  if  ( multipartRequestParsed)  { 
                
                this . cleanupMultipart ( processedRequest) ; 
            } 
        } 
    } 
    
    
    
    private  void  processDispatchResult ( HttpServletRequest  request,  HttpServletResponse  response,  @Nullable  HandlerExecutionChain  mappedHandler,  @Nullable  ModelAndView  mv,  @Nullable  Exception  exception)  throws  Exception  { 
        
        boolean  errorView =  false ; 
        
        if  ( exception !=  null )  { 
            if  ( exception instanceof  ModelAndViewDefiningException )  { 
                
                this . logger. debug ( "ModelAndViewDefiningException encountered" ,  exception) ; 
                mv =  ( ( ModelAndViewDefiningException ) exception) . getModelAndView ( ) ; 
            }  else  { 
                
                Object  handler =  mappedHandler !=  null  ?  mappedHandler. getHandler ( )  :  null ; 
                mv =  this . processHandlerException ( request,  response,  handler,  exception) ; 
                errorView =  mv !=  null ; 
            } 
        } 
        
        if  ( mv !=  null  &&  ! mv. wasCleared ( ) )  { 
            
            this . render ( mv,  request,  response) ; 
            
            if  ( errorView)  { 
                WebUtils . clearErrorRequestAttributes ( request) ; 
            } 
        }  else  if  ( this . logger. isTraceEnabled ( ) )  { 
            
            this . logger. trace ( "No view rendering, null ModelAndView returned." ) ; 
        } 
        
        if  ( ! WebAsyncUtils . getAsyncManager ( request) . isConcurrentHandlingStarted ( ) )  { 
            if  ( mappedHandler !=  null )  { 
                mappedHandler. triggerAfterCompletion ( request,  response,  ( Exception ) null ) ; 
            } 
        } 
    } 
    
    
     protected  void  render ( ModelAndView  mv,  HttpServletRequest  request,  HttpServletResponse  response)  throws  Exception  { 
         
        Locale  locale =  this . localeResolver !=  null  ?  this . localeResolver. resolveLocale ( request)  :  request. getLocale ( ) ; 
         
        response. setLocale ( locale) ; 
         
        String  viewName =  mv. getViewName ( ) ; 
        View  view; 
         
        if  ( viewName !=  null )  { 
            
            view =  this . resolveViewName ( viewName,  mv. getModelInternal ( ) ,  locale,  request) ; 
            if  ( view ==  null )  { 
                
                throw  new  ServletException ( "Could not resolve view with name '"  +  mv. getViewName ( )  +  "' in servlet with name '"  +  this . getServletName ( )  +  "'" ) ; 
            } 
        }  else  { 
           
            
            
            view =  mv. getView ( ) ; 
            if  ( view ==  null )  { 
                
                throw  new  ServletException ( "ModelAndView ["  +  mv +  "] neither contains a view name nor a View object in servlet with name '"  +  this . getServletName ( )  +  "'" ) ; 
            } 
        } 
         
        if  ( this . logger. isTraceEnabled ( ) )  { 
            this . logger. trace ( "Rendering view ["  +  view +  "] " ) ; 
        } 
        try  { 
            
            if  ( mv. getStatus ( )  !=  null )  { 
                response. setStatus ( mv. getStatus ( ) . value ( ) ) ; 
            } 
            
            view. render ( mv. getModelInternal ( ) ,  request,  response) ; 
        }  catch  ( Exception  var8)  { 
            
            if  ( this . logger. isDebugEnabled ( ) )  { 
                this . logger. debug ( "Error rendering view ["  +  view +  "]" ,  var8) ; 
            } 
            throw  var8; 
        } 
    } 
    
    
    @Nullable 
    protected  View  resolveViewName ( String  viewName,  @Nullable  Map < String ,  Object > ,  Locale  locale,  HttpServletRequest  request)  throws  Exception  { 
        
        if  ( this . viewResolvers !=  null )  { 
            
            Iterator  var5 =  this . viewResolvers. iterator ( ) ; 
            while ( var5. hasNext ( ) )  { 
                
                ViewResolver  viewResolver =  ( ViewResolver ) var5. next ( ) ; 
                
                View  view =  viewResolver. resolveViewName ( viewName,  locale) ; 
                if  ( view !=  null )  { 
                    
                    return  view; 
                } 
            } 
        } 
        return  null ; 
    } 
    
} 
public  abstract  class  FrameworkServlet  extends  HttpServletBean  implements  ApplicationContextAware  { 
 
 
     protected  void  service ( HttpServletRequest  request,  HttpServletResponse  response)  throws  ServletException ,  IOException  { 
        HttpMethod  httpMethod =  HttpMethod . resolve ( request. getMethod ( ) ) ; 
        if  ( httpMethod !=  HttpMethod . PATCH  &&  httpMethod !=  null )  { 
            
            super . service ( request,  response) ; 
        }  else  { 
            this . processRequest ( request,  response) ; 
        } 
    } 
       protected  final  void  doGet ( HttpServletRequest  request,  HttpServletResponse  response)  throws  ServletException ,  IOException  { 
        this . processRequest ( request,  response) ; 
    } 
    
    protected  final  void  doPost ( HttpServletRequest  request,  HttpServletResponse  response)  throws  ServletException ,  IOException  { 
        this . processRequest ( request,  response) ; 
    } 
     
    
    
     protected  final  void  processRequest ( HttpServletRequest  request,  HttpServletResponse  response)  throws  ServletException ,  IOException  { 
         
        long  startTime =  System . currentTimeMillis ( ) ; 
         
        Throwable  failureCause =  null ; 
         
        LocaleContext  previousLocaleContext =  LocaleContextHolder . getLocaleContext ( ) ; 
         
        LocaleContext  localeContext =  this . buildLocaleContext ( request) ; 
         
        RequestAttributes  previousAttributes =  RequestContextHolder . getRequestAttributes ( ) ; 
         
        ServletRequestAttributes  requestAttributes =  this . buildRequestAttributes ( request,  response,  previousAttributes) ; 
         
        WebAsyncManager  asyncManager =  WebAsyncUtils . getAsyncManager ( request) ; 
         
        asyncManager. registerCallableInterceptor ( FrameworkServlet . class . getName ( ) ,  new  FrameworkServlet. RequestBindingInterceptor ( ) ) ; 
         
        this . initContextHolders ( request,  localeContext,  requestAttributes) ; 
         
        try  { 
            
            this . doService ( request,  response) ;  
        }  catch  ( IOException  |  ServletException  var16)  { 
            failureCause =  var16; 
            throw  var16; 
        }  catch  ( Throwable  var17)  { 
            failureCause =  var17; 
            throw  new  NestedServletException ( "Request processing failed" ,  var17) ; 
        }  finally  { 
            
            this . resetContextHolders ( request,  previousLocaleContext,  previousAttributes) ; 
            
            
            if  ( requestAttributes !=  null )  { 
                requestAttributes. requestCompleted ( ) ; 
            } 
            
            this . logResult ( request,  response,  ( Throwable ) failureCause,  asyncManager) ; 
            this . publishRequestHandledEvent ( request,  response,  startTime,  ( Throwable ) failureCause) ; 
        } 
    } 
    
    
    protected  abstract  void  doService ( HttpServletRequest  var1,  HttpServletResponse  var2)  throws  Exception ; 
    
    
} 
public  abstract  class  HttpServletBean  extends  HttpServlet  implements  EnvironmentCapable ,  EnvironmentAware  { 
    
    
   
    
} 
public  abstract  class  HttpServlet  extends  GenericServlet  { 
 
     protected  void  doGet ( HttpServletRequest  req,  HttpServletResponse  resp)  throws  ServletException ,  IOException  { 
         
        String  protocol =  req. getProtocol ( ) ; 
         
        String  msg =  lStrings. getString ( "http.method_get_not_supported" ) ; 
         
        if  ( protocol. endsWith ( "1.1" ) )  { 
            resp. sendError ( 405 ,  msg) ;  
        }  else  { 
            resp. sendError ( 400 ,  msg) ;  
        } 
         
    } 
    
     protected  void  doPost ( HttpServletRequest  req,  HttpServletResponse  resp)  throws  ServletException ,  IOException  { 
        String  protocol =  req. getProtocol ( ) ; 
        String  msg =  lStrings. getString ( "http.method_post_not_supported" ) ; 
        if  ( protocol. endsWith ( "1.1" ) )  { 
            resp. sendError ( 405 ,  msg) ; 
        }  else  { 
            resp. sendError ( 400 ,  msg) ; 
        } 
    } 
    / . . 
    
    
    protected  void  service ( HttpServletRequest  req,  HttpServletResponse  resp)  throws  ServletException ,  IOException  { 
        String  method =  req. getMethod ( ) ; 
        long  lastModified; 
        if  ( method. equals ( "GET" ) )  { 
            lastModified =  this . getLastModified ( req) ; 
            if  ( lastModified ==  - 1L )  { 
                
                this . doGet ( req,  resp) ; 
            }  else  { 
                long  ifModifiedSince =  req. getDateHeader ( "If-Modified-Since" ) ; 
                if  ( ifModifiedSince <  lastModified)  { 
                    this . maybeSetLastModified ( resp,  lastModified) ; 
                    this . doGet ( req,  resp) ; 
                }  else  { 
                    resp. setStatus ( 304 ) ; 
                } 
            } 
        }  else  if  ( method. equals ( "HEAD" ) )  { 
            lastModified =  this . getLastModified ( req) ; 
            this . maybeSetLastModified ( resp,  lastModified) ; 
            this . doHead ( req,  resp) ; 
        }  else  if  ( method. equals ( "POST" ) )  { 
            
            this . doPost ( req,  resp) ; 
        }  else  if  ( method. equals ( "PUT" ) )  { 
            this . doPut ( req,  resp) ; 
        }  else  if  ( method. equals ( "DELETE" ) )  { 
            this . doDelete ( req,  resp) ; 
        }  else  if  ( method. equals ( "OPTIONS" ) )  { 
            this . doOptions ( req,  resp) ; 
        }  else  if  ( method. equals ( "TRACE" ) )  { 
            this . doTrace ( req,  resp) ; 
        }  else  { 
            String  errMsg =  lStrings. getString ( "http.method_not_implemented" ) ; 
            Object [ ]  errArgs =  new  Object [ ] { method} ; 
            errMsg =  MessageFormat . format ( errMsg,  errArgs) ; 
            resp. sendError ( 501 ,  errMsg) ; 
        } 
    } 
    
    
     public  void  service ( ServletRequest  req,  ServletResponse  res)  throws  ServletException ,  IOException  { 
        if  ( req instanceof  HttpServletRequest  &&  res instanceof  HttpServletResponse )  { 
            HttpServletRequest  request =  ( HttpServletRequest ) req; 
            HttpServletResponse  response =  ( HttpServletResponse ) res; 
            this . service ( request,  response) ; 
        }  else  { 
            throw  new  ServletException ( "non-HTTP request or response" ) ; 
        } 
    } 
     
} 
public  abstract  class  GenericServlet  implements  Servlet ,  ServletConfig ,  Serializable  { 
 
    
     public  abstract  void  service ( ServletRequest  var1,  ServletResponse  var2)  throws  ServletException ,  IOException ; 
     
} 
package  javax. servlet ; 
import  java. io.  IOException ; 
public  interface  Servlet  { 
    void  init ( ServletConfig  var1)  throws  ServletException ; 
    ServletConfig  getServletConfig ( ) ; 
    
    void  service ( ServletRequest  var1,  ServletResponse  var2)  throws  ServletException ,  IOException ; 
    String  getServletInfo ( ) ; 
    void  destroy ( ) ; 
} 
	< beanid = " viewResolver" class = " org.springframework.web.servlet.view.InternalResourceViewResolver" > < propertyname = " prefix" value = " /WEB-INF/jsp/" > </ property> < propertyname = " suffix" value = " .jsp" > </ property> </ bean> < mvc: annotation-driven> </ mvc: annotation-driven> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%System.out.println("跳转到页面");%>
跳转成功,${date}
</body>
</html>
@RequestMapping ( "/name" ) 
	public  String  fa ( String  name,  Map < String ,  Object > )  { 
		dome. fa ( name) ; 
		Date  date =  new  Date ( ) ; 
		map. put ( "date" ,  date) ; 
		return  "index" ; 
	} 
 
 
@RequestMapping ( "/name" ) 
	public  String  fa ( String  name,  Map < String ,  Object > )  { 
		
		dome. fa ( name) ; 
		Date  date =  new  Date ( ) ; 
		map. put ( "date" ,  date) ; 
		return  "index" ; 
	} 
 
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<!--下面一行打上断点-->
<%System.out.println("跳转到页面");%>
跳转成功,${date}
</body>
</html>
 
                    mappedHandler =  this . getHandler ( processedRequest) ; 
@Nullable 
	protected  HandlerExecutionChain  getHandler ( HttpServletRequest  request)  throws  Exception  { 
      
		if  ( this . handlerMappings !=  null )  { 
			for  ( HandlerMapping  mapping :  this . handlerMappings)  { 
				HandlerExecutionChain  handler =  mapping. getHandler ( request) ; 
				if  ( handler !=  null )  { 
					return  handler; 
				} 
			} 
		} 
		return  null ; 
	} 
 
dependencies {     
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'     
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'     
    implementation project ( ":spring-webmvc" )   
    implementation 'javax.servlet:javax.servlet-api:3.1.0'   
    providedCompile 'javax.servlet.jsp:jsp-api:2.2'    
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'    
    implementation 'com.fasterxml.jackson.core:jackson-core:2.9.8'   
    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.0' 
} 
System.out.println(mapping);
public  class  RequestMappingHandlerMapping  extends  RequestMappingInfoHandlerMapping 
		implements  MatchableHandlerMapping ,  EmbeddedValueResolverAware  { 
    
    
    
} 
public  abstract  class  RequestMappingInfoHandlerMapping  extends  AbstractHandlerMethodMapping < RequestMappingInfo > { 
    
} 
public  abstract  class  AbstractHandlerMethodMapping < T > extends  AbstractHandlerMapping  implements  InitializingBean  { 
 
} 
public  abstract  class  AbstractHandlerMapping  extends  WebApplicationObjectSupport 
		implements  HandlerMapping ,  Ordered ,  BeanNameAware  { 
 
    
    
    @Override 
	@Nullable 
	public  final  HandlerExecutionChain  getHandler ( HttpServletRequest  request)  throws  Exception  { 
        
        
		Object  handler =  getHandlerInternal ( request) ; 
		if  ( handler ==  null )  { 
            
			handler =  getDefaultHandler ( ) ; 
		} 
		if  ( handler ==  null )  { 
            
			return  null ; 
		} 
		
        
		if  ( handler instanceof  String )  { 
			String  handlerName =  ( String )  handler; 
			handler =  obtainApplicationContext ( ) . getBean ( handlerName) ; 
		} 
		HandlerExecutionChain  executionChain =  getHandlerExecutionChain ( handler,  request) ; 
        
		if  ( logger. isTraceEnabled ( ) )  { 
			logger. trace ( "Mapped to "  +  handler) ; 
		} 
		else  if  ( logger. isDebugEnabled ( )  &&  ! request. getDispatcherType ( ) . equals ( DispatcherType . ASYNC ) )  { 
			logger. debug ( "Mapped to "  +  executionChain. getHandler ( ) ) ; 
		} 
        
		if  ( CorsUtils . isCorsRequest ( request) )  { 
            
			CorsConfiguration  globalConfig =  this . corsConfigurationSource. getCorsConfiguration ( request) ; 
			CorsConfiguration  handlerConfig =  getCorsConfiguration ( handler,  request) ; 
            
			CorsConfiguration  config =  ( globalConfig !=  null  ?  globalConfig. combine ( handlerConfig)  :  handlerConfig) ; 
            
			executionChain =  getCorsHandlerExecutionChain ( request,  executionChain,  config) ; 
		} 
        
		return  executionChain; 
	} 
    
    
} 
                    HandlerAdapter  ha =  this . getHandlerAdapter ( mappedHandler. getHandler ( ) ) ; 
protected  HandlerAdapter  getHandlerAdapter ( Object  handler)  throws  ServletException  { 
    
		if  ( this . handlerAdapters !=  null )  { 
            
			for  ( HandlerAdapter  adapter :  this . handlerAdapters)  { 
                
                
                
				if  ( adapter. supports ( handler) )  { 
                    
					return  adapter; 
				} 
			} 
		} 
		throw  new  ServletException ( "No adapter for handler ["  +  handler + 
				"]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler" ) ; 
	} 
 
 
public  class  RequestMappingHandlerAdapter  extends  AbstractHandlerMethodAdapter 
		implements  BeanFactoryAware ,  InitializingBean  { 
 
    @Override 
	protected  boolean  supportsInternal ( HandlerMethod  handlerMethod)  { 
		return  true ; 
	} 
    
    
    
} 
public  abstract  class  AbstractHandlerMethodAdapter  extends  WebContentGenerator  implements  HandlerAdapter ,  Ordered  { 
    
    
    @Override 
	public  final  boolean  supports ( Object  handler)  { 
        
        
		return  ( handler instanceof  HandlerMethod  &&  supportsInternal ( ( HandlerMethod )  handler) ) ; 
	} 
    
 
} 
@SuppressWarnings ( "serial" ) 
public  class  DispatcherServlet  extends  FrameworkServlet  { 
 
    
    
	@Nullable 
	private  MultipartResolver  multipartResolver; 
	@Nullable 
	private  LocaleResolver  localeResolver; 
	@Nullable 
	private  ThemeResolver  themeResolver; 
	@Nullable 
	private  List < HandlerMapping > ; 
	@Nullable 
	private  List < HandlerAdapter > ; 
	@Nullable 
	private  List < HandlerExceptionResolver > ; 
	@Nullable 
	private  RequestToViewNameTranslator  viewNameTranslator; 
	@Nullable 
	private  FlashMapManager  flashMapManager; 
	@Nullable 
	private  List < ViewResolver > ; 
    
    
    
    
    
} 
    
@SuppressWarnings ( "serial" ) 
public  class  DispatcherServlet  extends  FrameworkServlet  { 
 
    
    
    
    
    @Override 
	protected  void  onRefresh ( ApplicationContext  context)  { 
		initStrategies ( context) ; 
	} 
    protected  void  initStrategies ( ApplicationContext  context)  { 
        
        
        
		initMultipartResolver ( context) ; 
        
		initLocaleResolver ( context) ; 
        
		initThemeResolver ( context) ; 
        
		initHandlerMappings ( context) ; 
        
		initHandlerAdapters ( context) ; 
        
		initHandlerExceptionResolvers ( context) ; 
        
		initRequestToViewNameTranslator ( context) ; 
        
		initViewResolvers ( context) ; 
        
		initFlashMapManager ( context) ; 
	} 
    
    
    
} 
 
 
private  void  initHandlerMappings ( ApplicationContext  context)  { 
		this . handlerMappings =  null ; 
    
		if  ( this . detectAllHandlerMappings)  { 
			
            
            
			Map < String ,  HandlerMapping > = 
					BeanFactoryUtils . beansOfTypeIncludingAncestors ( context,  HandlerMapping . class ,  true ,  false ) ; 
            
			if  ( ! matchingBeans. isEmpty ( ) )  { 
				this . handlerMappings =  new  ArrayList < > ( matchingBeans. values ( ) ) ; 
				
                
				AnnotationAwareOrderComparator . sort ( this . handlerMappings) ; 
			} 
		} 
    
		else  { 
			try  { 
                
				HandlerMapping  hm =  context. getBean ( HANDLER_MAPPING_BEAN_NAME ,  HandlerMapping . class ) ; 
                
				this . handlerMappings =  Collections . singletonList ( hm) ; 
			} 
			catch  ( NoSuchBeanDefinitionException  ex)  { 
                
				
			} 
		} 
		
		
    
		if  ( this . handlerMappings ==  null )  { 
            
			this . handlerMappings =  getDefaultStrategies ( context,  HandlerMapping . class ) ; 
            
			if  ( logger. isTraceEnabled ( ) )  { 
				logger. trace ( "No HandlerMappings declared for servlet '"  +  getServletName ( )  + 
						"': using default strategies from DispatcherServlet.properties" ) ; 
			} 
		} 
	} 
private  void  initMultipartResolver ( ApplicationContext  context)  { 
		try  { 
			this . multipartResolver =  context. getBean ( MULTIPART_RESOLVER_BEAN_NAME ,  MultipartResolver . class ) ; 
			if  ( logger. isTraceEnabled ( ) )  { 
				logger. trace ( "Detected "  +  this . multipartResolver) ; 
			} 
			else  if  ( logger. isDebugEnabled ( ) )  { 
				logger. debug ( "Detected "  +  this . multipartResolver. getClass ( ) . getSimpleName ( ) ) ; 
			} 
		} 
		catch  ( NoSuchBeanDefinitionException  ex)  { 
			
			this . multipartResolver =  null ; 
			if  ( logger. isTraceEnabled ( ) )  { 
				logger. trace ( "No MultipartResolver '"  +  MULTIPART_RESOLVER_BEAN_NAME  +  "' declared" ) ; 
			} 
		} 
	} 
this . multipartResolver =  context. getBean ( MULTIPART_RESOLVER_BEAN_NAME ,  MultipartResolver . class ) ; 
public  static  final  String  MULTIPART_RESOLVER_BEAN_NAME  =  "multipartResolver" ; 
 
                    mv =  ha. handle ( processedRequest,  response,  mappedHandler. getHandler ( ) ) ; 
public  class  RequestMappingHandlerAdapter  extends  AbstractHandlerMethodAdapter 
		implements  BeanFactoryAware ,  InitializingBean  { 
 
    
    
    
    @Override 
	protected  ModelAndView  handleInternal ( HttpServletRequest  request, 
			HttpServletResponse  response,  HandlerMethod  handlerMethod)  throws  Exception  { 
        
        
		ModelAndView  mav;  
		checkRequest ( request) ;  
		
        
        
		if  ( this . synchronizeOnSession)  { 
			HttpSession  session =  request. getSession ( false ) ;  
			if  ( session !=  null )  { 
                
				Object  mutex =  WebUtils . getSessionMutex ( session) ;  
                
				synchronized  ( mutex)  { 
                    
					mav =  invokeHandlerMethod ( request,  response,  handlerMethod) ; 
				} 
			} 
			else  { 
				
                
				mav =  invokeHandlerMethod ( request,  response,  handlerMethod) ; 
			} 
		} 
		else  { 
			
            
            
			mav =  invokeHandlerMethod ( request,  response,  handlerMethod) ; 
		} 
        
		if  ( ! response. containsHeader ( HEADER_CACHE_CONTROL ) )  { 
            
			if  ( getSessionAttributesHandler ( handlerMethod) . hasSessionAttributes ( ) )  { 
				applyCacheSeconds ( response,  this . cacheSecondsForSessionAttributeHandlers) ; 
			} 
			else  { 
                
				prepareResponse ( response) ; 
			} 
		} 
        
		return  mav; 
	} 
    
    
    
} 
public  abstract  class  AbstractHandlerMethodAdapter  extends  WebContentGenerator  implements  HandlerAdapter ,  Ordered  { 
    
    
    @Override 
	@Nullable 
	public  final  ModelAndView  handle ( HttpServletRequest  request,  HttpServletResponse  response,  Object  handler) 
			throws  Exception  { 
		return  handleInternal ( request,  response,  ( HandlerMethod )  handler) ; 
	} 
    
    
} 
@Nullable  
	protected  ModelAndView  invokeHandlerMethod ( HttpServletRequest  request, 
			HttpServletResponse  response,  HandlerMethod  handlerMethod)  throws  Exception  { 
        
		ServletWebRequest  webRequest =  new  ServletWebRequest ( request,  response) ; 
		try  { 
            
            
			WebDataBinderFactory  binderFactory =  getDataBinderFactory ( handlerMethod) ; 
            
            
			ModelFactory  modelFactory =  getModelFactory ( handlerMethod,  binderFactory) ; 
            
            
            
			ServletInvocableHandlerMethod  invocableMethod =  createInvocableHandlerMethod ( handlerMethod) ; 
            
			if  ( this . argumentResolvers !=  null )  { 
                
				invocableMethod. setHandlerMethodArgumentResolvers ( this . argumentResolvers) ; 
			} 
			if  ( this . returnValueHandlers !=  null )  { 
                
				invocableMethod. setHandlerMethodReturnValueHandlers ( this . returnValueHandlers) ; 
			} 
            
			invocableMethod. setDataBinderFactory ( binderFactory) ; 
			invocableMethod. setParameterNameDiscoverer ( this . parameterNameDiscoverer) ; 
            
			ModelAndViewContainer  mavContainer =  new  ModelAndViewContainer ( ) ; 
			mavContainer. addAllAttributes ( RequestContextUtils . getInputFlashMap ( request) ) ; 
            
            
            
            
			modelFactory. initModel ( webRequest,  mavContainer,  invocableMethod) ; 
			mavContainer. setIgnoreDefaultModelOnRedirect ( this . ignoreDefaultModelOnRedirect) ; 
            
			AsyncWebRequest  asyncWebRequest =  WebAsyncUtils . createAsyncWebRequest ( request,  response) ; 
			asyncWebRequest. setTimeout ( this . asyncRequestTimeout) ; 
            
			WebAsyncManager  asyncManager =  WebAsyncUtils . getAsyncManager ( request) ; 
			asyncManager. setTaskExecutor ( this . taskExecutor) ; 
			asyncManager. setAsyncWebRequest ( asyncWebRequest) ; 
			asyncManager. registerCallableInterceptors ( this . callableInterceptors) ; 
			asyncManager. registerDeferredResultInterceptors ( this . deferredResultInterceptors) ; 
            
			if  ( asyncManager. hasConcurrentResult ( ) )  { 
				Object  result =  asyncManager. getConcurrentResult ( ) ; 
				mavContainer =  ( ModelAndViewContainer )  asyncManager. getConcurrentResultContext ( ) [ 0 ] ; 
				asyncManager. clearConcurrentResult ( ) ; 
				LogFormatUtils . traceDebug ( logger,  traceOn ->  { 
					String  formatted =  LogFormatUtils . formatValue ( result,  ! traceOn) ; 
					return  "Resume with async result ["  +  formatted +  "]" ; 
				} ) ; 
				invocableMethod =  invocableMethod. wrapConcurrentResult ( result) ; 
			} 
            
            
            
			invocableMethod. invokeAndHandle ( webRequest,  mavContainer) ; 
            
			if  ( asyncManager. isConcurrentHandlingStarted ( ) )  { 
				return  null ; 
			} 
            
            
            
        
            
            
			return  getModelAndView ( mavContainer,  modelFactory,  webRequest) ; 
		} 
		finally  { 
            
			webRequest. requestCompleted ( ) ; 
		} 
	} 
public  class  ServletInvocableHandlerMethod  extends  InvocableHandlerMethod  { 
 
    
    public  void  invokeAndHandle ( ServletWebRequest  webRequest,  ModelAndViewContainer  mavContainer, 
			Object . . .  providedArgs)  throws  Exception  { 
        
		Object  returnValue =  invokeForRequest ( webRequest,  mavContainer,  providedArgs) ; 
        
		setResponseStatus ( webRequest) ; 
        
		if  ( returnValue ==  null )  { 
            
			if  ( isRequestNotModified ( webRequest)  ||  getResponseStatus ( )  !=  null  ||  mavContainer. isRequestHandled ( ) )  { 
				disableContentCachingIfNecessary ( webRequest) ; 
				mavContainer. setRequestHandled ( true ) ; 
				return ; 
			} 
		} 
        
		else  if  ( StringUtils . hasText ( getResponseStatusReason ( ) ) )  { 
             
			mavContainer. setRequestHandled ( true ) ; 
			return ; 
		} 
         
		mavContainer. setRequestHandled ( false ) ; 
        
		Assert . state ( this . returnValueHandlers !=  null ,  "No return value handlers" ) ; 
		try  { 
             
            
			this . returnValueHandlers. handleReturnValue ( 
					returnValue,  getReturnValueType ( returnValue) ,  mavContainer,  webRequest) ; 
		} 
		catch  ( Exception  ex)  { 
            
			if  ( logger. isTraceEnabled ( ) )  { 
				logger. trace ( formatErrorForReturnValue ( returnValue) ,  ex) ; 
			} 
			throw  ex; 
		} 
	} 
    
    
    
} 
public  class  ServletInvocableHandlerMethod  extends  InvocableHandlerMethod  { 
 
} 
public  class  InvocableHandlerMethod  extends  HandlerMethod  { 
 
    @Nullable 
	public  Object  invokeForRequest ( NativeWebRequest  request,  @Nullable  ModelAndViewContainer  mavContainer, 
			Object . . .  providedArgs)  throws  Exception  { 
        
		Object [ ]  args =  getMethodArgumentValues ( request,  mavContainer,  providedArgs) ; 
		if  ( logger. isTraceEnabled ( ) )  { 
			logger. trace ( "Arguments: "  +  Arrays . toString ( args) ) ; 
		} 
        
        
		return  doInvoke ( args) ; 
	} 
    
    
   @Nullable 
	protected  Object  doInvoke ( Object . . .  args)  throws  Exception  { 
		ReflectionUtils . makeAccessible ( getBridgedMethod ( ) ) ; 
		try  { 
            
			return  getBridgedMethod ( ) . invoke ( getBean ( ) ,  args) ; 
		} 
		catch  ( IllegalArgumentException  ex)  { 
			assertTargetBean ( getBridgedMethod ( ) ,  getBean ( ) ,  args) ; 
			String  text =  ( ex. getMessage ( )  !=  null  ?  ex. getMessage ( )  :  "Illegal argument" ) ; 
			throw  new  IllegalStateException ( formatInvokeError ( text,  args) ,  ex) ; 
		} 
		catch  ( InvocationTargetException  ex)  { 
			
			Throwable  targetException =  ex. getTargetException ( ) ; 
			if  ( targetException instanceof  RuntimeException )  { 
				throw  ( RuntimeException )  targetException; 
			} 
			else  if  ( targetException instanceof  Error )  { 
				throw  ( Error )  targetException; 
			} 
			else  if  ( targetException instanceof  Exception )  { 
				throw  ( Exception )  targetException; 
			} 
			else  { 
				throw  new  IllegalStateException ( formatInvokeError ( "Invocation failure" ,  args) ,  targetException) ; 
			} 
		} 
	} 
    
    
    protected  Object [ ]  getMethodArgumentValues ( NativeWebRequest  request,  @Nullable  ModelAndViewContainer  mavContainer, 
			Object . . .  providedArgs)  throws  Exception  { 
        
        
        
		MethodParameter [ ]  parameters =  getMethodParameters ( ) ;  
		if  ( ObjectUtils . isEmpty ( parameters) )  { 
			return  EMPTY_ARGS ; 
		} 
		Object [ ]  args =  new  Object [ parameters. length] ; 
		for  ( int  i =  0 ;  i <  parameters. length;  i++ )  { 
			MethodParameter  parameter =  parameters[ i] ; 
			parameter. initParameterNameDiscovery ( this . parameterNameDiscoverer) ; 
            
			args[ i]  =  findProvidedArgument ( parameter,  providedArgs) ; 
			if  ( args[ i]  !=  null )  { 
				continue ; 
			} 
            
            
			if  ( ! this . resolvers. supportsParameter ( parameter) )  { 
				throw  new  IllegalStateException ( formatArgumentError ( parameter,  "No suitable resolver" ) ) ; 
			} 
			try  { 
                
				args[ i]  =  this . resolvers. resolveArgument ( parameter,  mavContainer,  request,  this . dataBinderFactory) ; 
			} 
			catch  ( Exception  ex)  { 
				
				if  ( logger. isDebugEnabled ( ) )  { 
					String  exMsg =  ex. getMessage ( ) ; 
					if  ( exMsg !=  null  &&  ! exMsg. contains ( parameter. getExecutable ( ) . toGenericString ( ) ) )  { 
						logger. debug ( formatArgumentError ( parameter,  exMsg) ) ; 
					} 
				} 
				throw  ex; 
			} 
		} 
		return  args; 
	} 
    
    
    
    @Nullable 
	protected  Object  doInvoke ( Object . . .  args)  throws  Exception  { 
		ReflectionUtils . makeAccessible ( getBridgedMethod ( ) ) ; 
		try  { 
            
            
            
			return  getBridgedMethod ( ) . invoke ( getBean ( ) ,  args) ; 
		} 
		catch  ( IllegalArgumentException  ex)  { 
			assertTargetBean ( getBridgedMethod ( ) ,  getBean ( ) ,  args) ; 
			String  text =  ( ex. getMessage ( )  !=  null  ?  ex. getMessage ( )  :  "Illegal argument" ) ; 
			throw  new  IllegalStateException ( formatInvokeError ( text,  args) ,  ex) ; 
		} 
		catch  ( InvocationTargetException  ex)  { 
			
			Throwable  targetException =  ex. getTargetException ( ) ; 
			if  ( targetException instanceof  RuntimeException )  { 
				throw  ( RuntimeException )  targetException; 
			} 
			else  if  ( targetException instanceof  Error )  { 
				throw  ( Error )  targetException; 
			} 
			else  if  ( targetException instanceof  Exception )  { 
				throw  ( Exception )  targetException; 
			} 
			else  { 
				throw  new  IllegalStateException ( formatInvokeError ( "Invocation failure" ,  args) ,  targetException) ; 
			} 
		} 
	} 
    
    
    
} 
public  class  HandlerMethodArgumentResolverComposite  implements  HandlerMethodArgumentResolver  { 
    
    @Override 
	@Nullable 
	public  Object  resolveArgument ( MethodParameter  parameter,  @Nullable  ModelAndViewContainer  mavContainer, 
			NativeWebRequest  webRequest,  @Nullable  WebDataBinderFactory  binderFactory)  throws  Exception  { 
		HandlerMethodArgumentResolver  resolver =  getArgumentResolver ( parameter) ; 
		if  ( resolver ==  null )  { 
			throw  new  IllegalArgumentException ( "Unsupported parameter type ["  + 
					parameter. getParameterType ( ) . getName ( )  +  "]. supportsParameter should be called first." ) ; 
		} 
        
        
		return  resolver. resolveArgument ( parameter,  mavContainer,  webRequest,  binderFactory) ; 
	} 
    
    
} 
public  interface  HandlerMethodArgumentResolver  { 
    
 
} 
public  abstract  class  AbstractNamedValueMethodArgumentResolver  implements  HandlerMethodArgumentResolver  { 
    
    
    
    
    @Override 
		@Nullable 
		public  final  Object  resolveArgument ( MethodParameter  parameter,  @Nullable  ModelAndViewContainer  mavContainer, 
				NativeWebRequest  webRequest,  @Nullable  WebDataBinderFactory  binderFactory)  throws  Exception  { 
	
            
            
            
            
            
			NamedValueInfo  namedValueInfo =  getNamedValueInfo ( parameter) ; 
            
			MethodParameter  nestedParameter =  parameter. nestedIfOptional ( ) ; 
	
            
			Object  resolvedName =  resolveStringValue ( namedValueInfo. name) ; 
            
            
			if  ( resolvedName ==  null )  { 
				throw  new  IllegalArgumentException ( 
						"Specified name must not resolve to null: ["  +  namedValueInfo. name +  "]" ) ; 
			} 
	
            
            
			Object  arg =  resolveName ( resolvedName. toString ( ) ,  nestedParameter,  webRequest) ;  
            
            
            
            
            
            
            
            
			if  ( arg ==  null )  { 
				if  ( namedValueInfo. defaultValue !=  null )  { 
					arg =  resolveStringValue ( namedValueInfo. defaultValue) ; 
				} 
                
				else  if  ( namedValueInfo. required &&  ! nestedParameter. isOptional ( ) )  { 
					handleMissingValue ( namedValueInfo. name,  nestedParameter,  webRequest) ; 
				} 
				arg =  handleNullValue ( namedValueInfo. name,  arg,  nestedParameter. getNestedParameterType ( ) ) ; 
			} 
			else  if  ( "" . equals ( arg)  &&  namedValueInfo. defaultValue !=  null )  { 
				arg =  resolveStringValue ( namedValueInfo. defaultValue) ; 
			} 
	
			if  ( binderFactory !=  null )  { 
				WebDataBinder  binder =  binderFactory. createBinder ( webRequest,  null ,  namedValueInfo. name) ; 
				try  { 
					arg =  binder. convertIfNecessary ( arg,  parameter. getParameterType ( ) ,  parameter) ; 
				} 
				catch  ( ConversionNotSupportedException  ex)  { 
					throw  new  MethodArgumentConversionNotSupportedException ( arg,  ex. getRequiredType ( ) , 
							namedValueInfo. name,  parameter,  ex. getCause ( ) ) ; 
				} 
				catch  ( TypeMismatchException  ex)  { 
					throw  new  MethodArgumentTypeMismatchException ( arg,  ex. getRequiredType ( ) , 
							namedValueInfo. name,  parameter,  ex. getCause ( ) ) ; 
				} 
			} 
	
			handleResolvedValue ( arg,  namedValueInfo. name,  parameter,  mavContainer,  webRequest) ; 
	
			return  arg; 
		} 
    
    
    
} 
public  class  MapMethodProcessor  implements  HandlerMethodArgumentResolver ,  HandlerMethodReturnValueHandler  { 
 
    @Override 
	@Nullable 
	public  Object  resolveArgument ( MethodParameter  parameter,  @Nullable  ModelAndViewContainer  mavContainer, 
			NativeWebRequest  webRequest,  @Nullable  WebDataBinderFactory  binderFactory)  throws  Exception  { 
		Assert . state ( mavContainer !=  null ,  "ModelAndViewContainer is required for model exposure" ) ; 
		return  mavContainer. getModel ( ) ;  
	} 
    
    
    
    
    
} 
public  class  ModelAndViewContainer  { 
    
    	public  ModelMap  getModel ( )  { 
		if  ( useDefaultModel ( ) )  { 
			return  this . defaultModel;  
            
		} 
		else  { 
			if  ( this . redirectModel ==  null )  { 
				this . redirectModel =  new  ModelMap ( ) ; 
			} 
			return  this . redirectModel; 
		} 
	} 
    
    
} 
mv =  ha. handle ( processedRequest,  response,  mappedHandler. getHandler ( ) ) ; 
                this . processDispatchResult ( processedRequest,  response,  mappedHandler,  mv,  ( Exception ) dispatchException) ; 
public  class  DispatcherServlet  extends  FrameworkServlet  { 
 
    
 
    
    private  void  processDispatchResult ( HttpServletRequest  request,  HttpServletResponse  response,  @Nullable  HandlerExecutionChain  mappedHandler,  @Nullable  ModelAndView  mv,  @Nullable  Exception  exception)  throws  Exception  { 
        
        boolean  errorView =  false ; 
        
        if  ( exception !=  null )  { 
            if  ( exception instanceof  ModelAndViewDefiningException )  { 
                
                this . logger. debug ( "ModelAndViewDefiningException encountered" ,  exception) ; 
                mv =  ( ( ModelAndViewDefiningException ) exception) . getModelAndView ( ) ; 
            }  else  { 
                
                Object  handler =  mappedHandler !=  null  ?  mappedHandler. getHandler ( )  :  null ; 
                mv =  this . processHandlerException ( request,  response,  handler,  exception) ; 
                errorView =  mv !=  null ; 
            } 
        } 
        
        if  ( mv !=  null  &&  ! mv. wasCleared ( ) )  { 
            
            this . render ( mv,  request,  response) ; 
            
            if  ( errorView)  { 
                WebUtils . clearErrorRequestAttributes ( request) ; 
            } 
        }  else  if  ( this . logger. isTraceEnabled ( ) )  { 
            
            this . logger. trace ( "No view rendering, null ModelAndView returned." ) ; 
        } 
        
        if  ( ! WebAsyncUtils . getAsyncManager ( request) . isConcurrentHandlingStarted ( ) )  { 
            if  ( mappedHandler !=  null )  { 
                mappedHandler. triggerAfterCompletion ( request,  response,  ( Exception ) null ) ; 
            } 
        } 
    } 
    
    
     protected  void  render ( ModelAndView  mv,  HttpServletRequest  request,  HttpServletResponse  response)  throws  Exception  { 
         
        Locale  locale =  this . localeResolver !=  null  ?  this . localeResolver. resolveLocale ( request)  :  request. getLocale ( ) ; 
         
        response. setLocale ( locale) ; 
         
        String  viewName =  mv. getViewName ( ) ; 
        View  view; 
         
        if  ( viewName !=  null )  { 
            
            view =  this . resolveViewName ( viewName,  mv. getModelInternal ( ) ,  locale,  request) ; 
            if  ( view ==  null )  { 
                
                throw  new  ServletException ( "Could not resolve view with name '"  +  mv. getViewName ( )  +  "' in servlet with name '"  +  this . getServletName ( )  +  "'" ) ; 
            } 
        }  else  { 
           
            
            
            view =  mv. getView ( ) ; 
            if  ( view ==  null )  { 
                
                throw  new  ServletException ( "ModelAndView ["  +  mv +  "] neither contains a view name nor a View object in servlet with name '"  +  this . getServletName ( )  +  "'" ) ; 
            } 
        } 
         
        if  ( this . logger. isTraceEnabled ( ) )  { 
            this . logger. trace ( "Rendering view ["  +  view +  "] " ) ; 
        } 
        try  { 
            
            if  ( mv. getStatus ( )  !=  null )  { 
                response. setStatus ( mv. getStatus ( ) . value ( ) ) ; 
            } 
            
            view. render ( mv. getModelInternal ( ) ,  request,  response) ; 
        }  catch  ( Exception  var8)  { 
            
            if  ( this . logger. isDebugEnabled ( ) )  { 
                this . logger. debug ( "Error rendering view ["  +  view +  "]" ,  var8) ; 
            } 
            throw  var8; 
        } 
    } 
    
    
    @Nullable 
    protected  View  resolveViewName ( String  viewName,  @Nullable  Map < String ,  Object > ,  Locale  locale,  HttpServletRequest  request)  throws  Exception  { 
        
        if  ( this . viewResolvers !=  null )  { 
            
            Iterator  var5 =  this . viewResolvers. iterator ( ) ; 
            while ( var5. hasNext ( ) )  { 
                
                ViewResolver  viewResolver =  ( ViewResolver ) var5. next ( ) ; 
                
                View  view =  viewResolver. resolveViewName ( viewName,  locale) ; 
                if  ( view !=  null )  { 
                    
                    return  view; 
                } 
            } 
        } 
        return  null ; 
    } 
    
    
} 
  
public  class  InternalResourceViewResolver  extends  UrlBasedViewResolver  { 
 
} 
public  class  UrlBasedViewResolver  extends  AbstractCachingViewResolver  implements  Ordered  { 
} 
public  abstract  class  AbstractCachingViewResolver  extends  WebApplicationObjectSupport  implements  ViewResolver  { 
    
    
    @Override 
	@Nullable 
	public  View  resolveViewName ( String  viewName,  Locale  locale)  throws  Exception  { 
        
		if  ( ! isCache ( ) )  { 
            
			return  createView ( viewName,  locale) ; 
		} 
		else  { 
            
			Object  cacheKey =  getCacheKey ( viewName,  locale) ; 
            
			View  view =  this . viewAccessCache. get ( cacheKey) ; 
            
			if  ( view ==  null )  { 
				synchronized  ( this . viewCreationCache)  { 
                    
					view =  this . viewCreationCache. get ( cacheKey) ; 
					if  ( view ==  null )  { 
                        
						
                        
						view =  createView ( viewName,  locale) ; 
						if  ( view ==  null  &&  this . cacheUnresolved)  { 
                            
							view =  UNRESOLVED_VIEW ; 
						} 
						if  ( view !=  null )  { 
                            
							this . viewAccessCache. put ( cacheKey,  view) ; 
							this . viewCreationCache. put ( cacheKey,  view) ; 
						} 
					} 
				} 
			} 
			else  { 
                
				if  ( logger. isTraceEnabled ( ) )  { 
					logger. trace ( formatKey ( cacheKey)  +  "served from cache" ) ; 
				} 
			} 
            
			return  ( view !=  UNRESOLVED_VIEW  ?  view :  null ) ; 
		} 
	} 
    
    
    
} 
public  class  InternalResourceViewResolver  extends  UrlBasedViewResolver  { 
 
} 
public  abstract  class  AbstractCachingViewResolver  extends  WebApplicationObjectSupport  implements  ViewResolver  { 
 
} 
public  class  UrlBasedViewResolver  extends  AbstractCachingViewResolver  implements  Ordered  { 
 
    @Override 
	protected  View  createView ( String  viewName,  Locale  locale)  throws  Exception  { 
		
		
        
		if  ( ! canHandle ( viewName,  locale) )  { 
			return  null ; 
		} 
		
		if  ( viewName. startsWith ( REDIRECT_URL_PREFIX ) )  { 
            
			String  redirectUrl =  viewName. substring ( REDIRECT_URL_PREFIX . length ( ) ) ; 
            
			RedirectView  view =  new  RedirectView ( redirectUrl, 
					isRedirectContextRelative ( ) ,  isRedirectHttp10Compatible ( ) ) ; 
            
			String [ ]  hosts =  getRedirectHosts ( ) ; 
			if  ( hosts !=  null )  { 
				view. setHosts ( hosts) ; 
			} 
            
			return  applyLifecycleMethods ( REDIRECT_URL_PREFIX ,  view) ; 
		} 
		
        
		if  ( viewName. startsWith ( FORWARD_URL_PREFIX ) )  { 
            
			String  forwardUrl =  viewName. substring ( FORWARD_URL_PREFIX . length ( ) ) ; 
            
			InternalResourceView  view =  new  InternalResourceView ( forwardUrl) ; 
            
			return  applyLifecycleMethods ( FORWARD_URL_PREFIX ,  view) ; 
		} 
        
        
        
        
        
		
		return  super . createView ( viewName,  locale) ; 
	} 
    
} 
public  abstract  class  AbstractCachingViewResolver  extends  WebApplicationObjectSupport  implements  ViewResolver  { 
@Nullable 
	protected  View  createView ( String  viewName,  Locale  locale)  throws  Exception  { 
		return  loadView ( viewName,  locale) ; 
	} 
    
} 
public  class  UrlBasedViewResolver  extends  AbstractCachingViewResolver  implements  Ordered  { 
    
    private  String  prefix =  "" ; 
	private  String  suffix =  "" ; 
    
    	protected  String  getPrefix ( )  { 
		return  this . prefix; 
	} 
    
    protected  String  getSuffix ( )  { 
		return  this . suffix; 
	} 
 
    	@Override 
	protected  View  loadView ( String  viewName,  Locale  locale)  throws  Exception  { 
        
		AbstractUrlBasedView  view =  buildView ( viewName) ;  
        
        
		View  result =  applyLifecycleMethods ( viewName,  view) ; 
        
		return  ( view. checkResource ( locale)  ?  result :  null ) ; 
	} 
    
  
    protected  AbstractUrlBasedView  buildView ( String  viewName)  throws  Exception  { 
        
		Class < ? > =  getViewClass ( ) ; 
        
		Assert . state ( viewClass !=  null ,  "No view class" ) ; 
        
		AbstractUrlBasedView  view =  ( AbstractUrlBasedView )  BeanUtils . instantiateClass ( viewClass) ; 
        
        
		view. setUrl ( getPrefix ( )  +  viewName +  getSuffix ( ) ) ; 
        
		String  contentType =  getContentType ( ) ; 
        
		if  ( contentType !=  null )  { 
			view. setContentType ( contentType) ; 
		} 
        
		view. setRequestContextAttribute ( getRequestContextAttribute ( ) ) ; 
        
		view. setAttributesMap ( getAttributesMap ( ) ) ; 
        
		Boolean  exposePathVariables =  getExposePathVariables ( ) ; 
        
		if  ( exposePathVariables !=  null )  { 
			view. setExposePathVariables ( exposePathVariables) ; 
		} 
        
		Boolean  exposeContextBeansAsAttributes =  getExposeContextBeansAsAttributes ( ) ; 
        
		if  ( exposeContextBeansAsAttributes !=  null )  { 
			view. setExposeContextBeansAsAttributes ( exposeContextBeansAsAttributes) ; 
		} 
        
		String [ ]  exposedContextBeanNames =  getExposedContextBeanNames ( ) ; 
        
		if  ( exposedContextBeanNames !=  null )  { 
			view. setExposedContextBeanNames ( exposedContextBeanNames) ; 
		} 
        
		return  view; 
	} 
    
    
} 
public  class  InternalResourceViewResolver  extends  UrlBasedViewResolver  { 
    
    	@Override 
	protected  AbstractUrlBasedView  buildView ( String  viewName)  throws  Exception  { 
        
		InternalResourceView  view =  ( InternalResourceView )  super . buildView ( viewName) ; 
		if  ( this . alwaysInclude !=  null )  { 
			view. setAlwaysInclude ( this . alwaysInclude) ; 
		} 
		view. setPreventDispatchLoop ( true ) ; 
		return  view; 
	} 
} 
            view =  this . resolveViewName ( viewName,  mv. getModelInternal ( ) ,  locale,  request) ; 
            view. render ( mv. getModelInternal ( ) ,  request,  response) ; 
public  class  InternalResourceView  extends  AbstractUrlBasedView  { 
 
} 
public  abstract  class  AbstractUrlBasedView  extends  AbstractView  implements  InitializingBean  { 
 
} 
public  abstract  class  AbstractView  extends  WebApplicationObjectSupport  implements  View ,  BeanNameAware  { 
    
    
    @Override 
	public  void  render ( @Nullable  Map < String ,  ? > ,  HttpServletRequest  request, 
			HttpServletResponse  response)  throws  Exception  { 
        
		if  ( logger. isDebugEnabled ( ) )  { 
             
			logger. debug ( "View "  +  formatViewName ( )  + 
					", model "  +  ( model !=  null  ?  model :  Collections . emptyMap ( ) )  + 
					( this . staticAttributes. isEmpty ( )  ?  ""  :  ", static attributes "  +  this . staticAttributes) ) ; 
		} 
        
        
        
		Map < String ,  Object > =  createMergedOutputModel ( model,  request,  response) ; 
        
		prepareResponse ( request,  response) ; 
        
		renderMergedOutputModel ( mergedModel,  getRequestToExpose ( request) ,  response) ; 
	} 
    
    
    
} 
public  class  InternalResourceView  extends  AbstractUrlBasedView  { 
 
    
    
    @Override 
	protected  void  renderMergedOutputModel ( 
			Map < String ,  Object > ,  HttpServletRequest  request,  HttpServletResponse  response)  throws  Exception  { 
        
		
		exposeModelAsRequestAttributes ( model,  request) ; 
        
		
		exposeHelpers ( request) ; 
		
		String  dispatcherPath =  prepareForRendering ( request,  response) ; 
        
		
		RequestDispatcher  rd =  getRequestDispatcher ( request,  dispatcherPath) ; 
		if  ( rd ==  null )  { 
			throw  new  ServletException ( "Could not get RequestDispatcher for ["  +  getUrl ( )  + 
					"]: Check that the corresponding file exists within your web application archive!" ) ; 
		} 
        
		
		if  ( useInclude ( request,  response) )  { 
            
			response. setContentType ( getContentType ( ) ) ; 
			if  ( logger. isDebugEnabled ( ) )  { 
				logger. debug ( "Including ["  +  getUrl ( )  +  "]" ) ; 
			} 
            
			rd. include ( request,  response) ; 
		} 
		else  { 
            
			
			if  ( logger. isDebugEnabled ( ) )  { 
				logger. debug ( "Forwarding to ["  +  getUrl ( )  +  "]" ) ; 
			} 
             
			rd. forward ( request,  response) ; 
		} 
	} 
    
    
} 
 
<?xml version="1.0" encoding="UTF-8"?> 
< projectxmlns = " http://maven.apache.org/POM/4.0.0" xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation= " http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion> </ modelVersion> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> < properties> < maven.compiler.source> </ maven.compiler.source> < maven.compiler.target> </ maven.compiler.target> </ properties> < packaging> </ packaging> < dependencies> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> < scope> </ scope> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> </ dependencies> </ project>  
        < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> 
 
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/bank?characterEncoding=utf8&useSSL=false
jdbc.username=root
jdbc.password=123456
CREATE  DATABASE  bank CHARACTER  SET  utf8; 
USE  bank; 
CREATE  TABLE  test( 
id INT ( 2 ) , 
NAME VARCHAR ( 10 ) 
) ; 
INSERT  INTO  test VALUE ( 1 , '张三' ) ; 
INSERT  INTO  test VALUE ( 2 , '李四' ) ; 
INSERT  INTO  test VALUE ( 3 , '王五' ) ; 
INSERT  INTO  test VALUE ( 4 , '赵六' ) ; 
<?xml version="1.0" encoding="UTF-8"?> 
< beansxmlns = " http://www.springframework.org/schema/beans" xmlns: context= " http://www.springframework.org/schema/context" xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation= " 
 http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context.xsd
" > < context: component-scanbase-package = " com.mapper" /> < context: property-placeholderlocation = " classpath:jdbc.properties" /> < beanid = " dataSource" class = " com.alibaba.druid.pool.DruidDataSource" > < propertyname = " driverClassName" value = " ${jdbc.driver}" /> < propertyname = " url" value = " ${jdbc.url}" /> < propertyname = " username" value = " ${jdbc.username}" /> < propertyname = " password" value = " ${jdbc.password}" /> </ bean> < beanid = " sqlSessionFactory" class = " org.mybatis.spring.SqlSessionFactoryBean" > < propertyname = " typeAliasesPackage" value = " com.pojo" /> < propertyname = " dataSource" ref = " dataSource" /> </ bean> < beanclass = " org.mybatis.spring.mapper.MapperScannerConfigurer" > < propertyname = " basePackage" value = " com.mapper" /> < propertyname = " sqlSessionFactoryBeanName" value = " sqlSessionFactory" /> </ bean> </ beans> <?xml version="1.0" encoding="UTF-8"?> 
< beansxmlns = " http://www.springframework.org/schema/beans" xmlns: context= " http://www.springframework.org/schema/context" xmlns: tx= " http://www.springframework.org/schema/tx" xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation= " 
 http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx.xsd
" > < context: property-placeholderlocation = " classpath:jdbc.properties" /> < beanid = " dataSource" class = " com.alibaba.druid.pool.DruidDataSource" > < propertyname = " driverClassName" value = " ${jdbc.driver}" /> < propertyname = " url" value = " ${jdbc.url}" /> < propertyname = " username" value = " ${jdbc.username}" /> < propertyname = " password" value = " ${jdbc.password}" /> </ bean> < context: component-scanbase-package = " com.service" /> < beanid = " transactionManager" class = " org.springframework.jdbc.datasource.DataSourceTransactionManager" > < propertyname = " dataSource" ref = " dataSource" /> </ bean> < tx: annotation-driventransaction-manager = " transactionManager" /> </ beans> package  com. mapper ; 
public  interface  AccountMapper  { 
    
    List < Account > queryAccountList ( )  throws  Exception ; 
} 
package  com. pojo ; 
public  class  Account  { 
    int  id; 
    String  name; 
    public  Account ( )  { 
    } 
    public  Account ( int  id,  String  name)  { 
        this . id =  id; 
        this . name =  name; 
    } 
    @Override 
    public  String  toString ( )  { 
        return  "Account{"  + 
                "id="  +  id + 
                ", name='"  +  name +  '\''  + 
                '}' ; 
    } 
    public  int  getId ( )  { 
        return  id; 
    } 
    public  void  setId ( int  id)  { 
        this . id =  id; 
    } 
    public  String  getName ( )  { 
        return  name; 
    } 
    public  void  setName ( String  name)  { 
        this . name =  name; 
    } 
} 
<! DOCTYPE  mapper  PUBLIC  "-//mybatis.org//DTD Mapper 3.0//EN" 
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > < mappernamespace = " com.mapper.AccountMapper" > < selectid = " queryAccountList" resultType = " com.pojo.Account" > </ select> </ mapper> package  com. service ; 
import  com. pojo.  Account ; 
import  java. util.  List ; 
public  interface  AccountService  { 
    List < Account > queryAccountList ( )  throws  Exception ; 
} 
package  com. service. impl ; 
import  com. mapper.  AccountMapper ; 
import  com. pojo.  Account ; 
import  com. service.  AccountService ; 
import  org. springframework. beans. factory. annotation.  Autowired ; 
import  java. util.  List ; 
@Service 
public  class  AccountServiceImpl  implements  AccountService  { 
    @Autowired 
    private  AccountMapper  accountMapper; 
    @Override 
    public  List < Account > queryAccountList ( )  throws  Exception  { 
        return  accountMapper. queryAccountList ( ) ; 
    } 
} 
package  test ; 
import  com. pojo.  Account ; 
import  com. service.  AccountService ; 
import  org. junit.  Test ; 
import  org. junit. runner.  RunWith ; 
import  org. springframework. beans. factory. annotation.  Autowired ; 
import  org. springframework. test. context.  ContextConfiguration ; 
import  org. springframework. test. context. junit4.  SpringJUnit4ClassRunner ; 
import  java. util.  List ; 
@RunWith ( SpringJUnit4ClassRunner . class ) 
@ContextConfiguration ( locations =  { "classpath*:application*.xml" } ) 
public  class  Test1  { 
    
    @Autowired 
    private  AccountService  accountService; 
    @Test 
    public  void  testMybatisSpring ( )  throws  Exception  { 
        List < Account > =  accountService. queryAccountList ( ) ; 
        for  ( int  i =  0 ;  i <  accounts. size ( ) ;  i++ )  { 
            Account  account =  accounts. get ( i) ; 
            System . out. println ( account) ; 
        } 
    } 
} 
        < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> < scope> </ scope> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> < scope> </ scope> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> <?xml version="1.0" encoding="UTF-8"?> 
< beansxmlns = " http://www.springframework.org/schema/beans" xmlns: mvc= " http://www.springframework.org/schema/mvc" xmlns: context= " http://www.springframework.org/schema/context" xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation= " http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/mvc
         http://www.springframework.org/schema/mvc/spring-mvc.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context.xsd" > < context: component-scanbase-package = " com.controller" /> < mvc: annotation-driven/> </ beans> package  com. controller ; 
import  com. pojo.  Account ; 
import  com. service.  AccountService ; 
import  org. springframework. beans. factory. annotation.  Autowired ; 
import  org. springframework. stereotype.  Controller ; 
import  org. springframework. web. bind. annotation.  RequestMapping ; 
import  org. springframework. web. bind. annotation.  ResponseBody ; 
import  javax. servlet.  ServletConfig ; 
import  javax. servlet.  ServletContext ; 
import  javax. servlet. http.  HttpServletRequest ; 
import  java. util.  List ; 
@Controller 
@RequestMapping ( "/account" ) 
public  class  AccountController  { 
    @Autowired 
    private  AccountService  accountService; 
    @RequestMapping ( "/queryAll" ) 
    @ResponseBody 
    
    public  List < Account > queryAll ( HttpServletRequest  request)  throws  Exception  { 
        ServletContext  context =  request. getSession ( ) . getServletContext ( ) ; 
        String  displayName =  context. getServletContextName ( ) ; 
        
        
        System . out. println ( "Display Name: "  +  displayName) ; 
        return  accountService. queryAccountList ( ) ; 
    } 
} 
<! DOCTYPE  web-app  PUBLIC 
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
        "http://java.sun.com/dtd/web-app_2_3.dtd"  > < web-app> < display-name> </ display-name> < context-param> < param-name> </ param-name> < param-value> </ param-value> </ context-param> < filter> < filter-name> </ filter-name> < filter-class> </ filter-class> < init-param> < param-name> </ param-name> < param-value> </ param-value> </ init-param> < init-param> < param-name> </ param-name> < param-value> </ param-value> </ init-param> </ filter> < filter-mapping> < filter-name> </ filter-name> < url-pattern> </ url-pattern> </ filter-mapping> < listener> < listener-class> </ listener-class> </ listener> < servlet> < servlet-name> </ servlet-name> < servlet-class> </ servlet-class> < init-param> < param-name> </ param-name> < param-value> </ param-value> </ init-param> < load-on-startup> </ load-on-startup> </ servlet> < servlet-mapping> < servlet-name> </ servlet-name> < url-pattern> </ url-pattern> </ servlet-mapping> </ web-app> <?xml version="1.0" encoding="UTF-8"?> 
 
< build> < plugins> < plugin> </ plugin> </ plugins> </ build> package  com ; 
import  java. text.  MessageFormat ; 
public  class  BuyGoods  { 
    private  String  goods; 
    private  double  price; 
    private  double  finalPrice; 
    private  String  desc; 
    public  BuyGoods ( String  goods,  double  price)  { 
        this . goods =  goods; 
        this . price =  price; 
    } 
    public  double  calculate ( String  discountType)  { 
        if  ( "discount85" . equals ( discountType) )  { 
            finalPrice =  price *  0.85 ; 
            desc =  "该商品可享受8.5折优惠" ; 
        }  else  if  ( "discount6" . equals ( discountType) )  { 
            finalPrice =  price *  0.6 ; 
            desc =  "该商品可享受6折优惠" ; 
        }  else  if  ( "return5" . equals ( discountType) )  { 
            finalPrice =  price >=  5  ?  price -  5  :  0 ; 
            desc =  "该商品可返现5元" ; 
        }  else  { 
            finalPrice =  price; 
            desc =  "对不起,该商品不参与优惠活动" ; 
        } 
        
        System . out. println ( MessageFormat . format ( "您购买的商品为:{0},原价为: {1},{2},最终售卖价格为:{3}" ,  goods,  price,  desc,  finalPrice) ) ; 
        return  finalPrice; 
    } 
} 
package  com ; 
public  class  Test  { 
    public  static  void  main ( String [ ]  args)  { 
        BuyGoods  buyGoods1 =  new  BuyGoods ( "Java编程思想" ,  99.00 ) ; 
        buyGoods1. calculate ( "discount85" ) ; 
        BuyGoods  buyGoods2 =  new  BuyGoods ( "罗技⿏标" ,  66 ) ; 
        buyGoods2. calculate ( "discount6" ) ; 
        BuyGoods  buyGoods3 =  new  BuyGoods ( "苹果笔记本" ,  15000.00 ) ; 
        buyGoods3. calculate ( "return5" ) ; 
        BuyGoods  buyGoods4 =  new  BuyGoods ( "佳能相机" ,  1900 ) ; 
        buyGoods4. calculate ( null ) ; 
    } 
} 
package  com ; 
public  abstract  class  AbstractDiscount  { 
    protected  double  finalPrice; 
    protected  String  desc; 
    public  AbstractDiscount ( String  desc)  { 
        this . desc =  desc; 
    } 
    public  abstract  double  discount ( double  price) ; 
    public  double  getFinalPrice ( )  { 
        return  finalPrice; 
    } 
    public  void  setFinalPrice ( double  finalPrice)  { 
        this . finalPrice =  finalPrice; 
    } 
    public  String  getDesc ( )  { 
        return  desc; 
    } 
    public  void  setDesc ( String  desc)  { 
        this . desc =  desc; 
    } 
} 
package  com ; 
public  class  Discount85  extends  AbstractDiscount  { 
    public  Discount85 ( )  { 
        super ( "该商品可享受8.5折优惠" ) ; 
    } 
    @Override 
    public  double  discount ( double  price)  { 
        finalPrice =  price *  0.85 ; 
        return  finalPrice; 
    } 
} 
package  com ; 
public  class  Discount6  extends  AbstractDiscount  { 
    public  Discount6 ( )  { 
        super ( "该商品可享受6折优惠" ) ; 
    } 
    @Override 
    public  double  discount ( double  price)  { 
        finalPrice =  price *  0.6 ; 
        return  finalPrice; 
    } 
} 
package  com ; 
public  class  Return5  extends  AbstractDiscount  { 
    public  Return5 ( )  { 
        super ( "该商品可返现5元" ) ; 
    } 
    @Override 
    public  double  discount ( double  price)  { 
        this . finalPrice =  price >=  5  ?  price -  5  :  0 ; 
        return  finalPrice; 
    } 
} 
package  com ; 
public  class  NoDiscount  extends  AbstractDiscount  { 
    public  NoDiscount ( )  { 
        super ( "对不起,该商品不参与优惠活动" ) ; 
    } 
    @Override 
    public  double  discount ( double  price)  { 
        finalPrice =  price; 
        return  finalPrice; 
    } 
} 
package  com ; 
import  java. text.  MessageFormat ; 
public  class  BuyGoods  { 
    private  String  goods; 
    private  double  price; 
    private  AbstractDiscount  abstractDiscount; 
    public  BuyGoods ( String  goods,  double  price,  AbstractDiscount  abstractDiscount)  { 
        this . goods =  goods; 
        this . price =  price; 
        this . abstractDiscount =  abstractDiscount; 
    } 
    public  double  calculate ( )  { 
        double  finalPrice =  abstractDiscount. discount ( this . price) ; 
        String  desc =  abstractDiscount. getDesc ( ) ; 
        System . out. println ( MessageFormat . format ( "商品:{0},原价:{1},{2},最 终价格为:{3}" ,  goods,  price,  desc,  finalPrice) ) ; 
        return  finalPrice; 
    } 
} 
package  com ; 
public  class  Test  { 
    public  static  void  main ( String [ ]  args)  { 
        BuyGoods  buyGoods1 =  new  BuyGoods ( "Java编程思想" ,  99.00 ,  new  Discount85 ( ) ) ; 
        buyGoods1. calculate ( ) ; 
        BuyGoods  buyGoods2 =  new  BuyGoods ( "罗技⿏标" ,  66 ,  new  Discount6 ( ) ) ; 
        buyGoods2. calculate ( ) ; 
        BuyGoods  buyGoods3 =  new  BuyGoods ( "苹果笔记本" ,  15000.00 ,  new  Return5 ( ) ) ; 
        buyGoods3. calculate ( ) ; 
        BuyGoods  buyGoods4 =  new  BuyGoods ( "佳能相机" ,  1900 ,  new  NoDiscount ( ) ) ; 
        buyGoods4. calculate ( ) ; 
    } 
} 
package  com. moban ; 
public  abstract  class  Interview  { 
    private  final  void  register ( )  { 
        System . out. println ( "⾯试登记" ) ; 
    } 
    protected  abstract  void  communicate ( ) ; 
    private  final  void  notifyResult ( )  { 
        System . out. println ( "HR⼩姐姐通知⾯试结果" ) ; 
    } 
    protected  final  void  process ( )  { 
        this . register ( ) ; 
        this . communicate ( ) ; 
        this . notifyResult ( ) ; 
    } 
} 
package  com. moban ; 
public  class  Interviewee1  extends  Interview  { 
    public  void  communicate ( )  { 
        System . out. println ( "我是⾯试⼈员1,来⾯试Java⼯程师,我们聊的是Java相关内容" ) ; 
    } 
} 
package  com. moban ; 
public  class  Interviewee2  extends  Interview  { 
    public  void  communicate ( )  { 
        System . out. println ( "我是⾯试⼈员2,来⾯试前端工程师,我们聊的是前端相关内容" ) ; 
    } 
} 
package  com. moban ; 
public  class  InterviewTest  { 
    public  static  void  main ( String [ ]  args)  { 
        
        Interview  interviewee1 =  new  Interviewee1 ( ) ; 
        interviewee1. process ( ) ; 
        
        Interview  interviewee2 =  new  Interviewee2 ( ) ; 
        interviewee2. process ( ) ; 
    } 
} 
  protected   void  communicate ( ) { 
        System . out. println ( 1 ) ; 
    } 
package  com. shipei ; 
public  class  AC220  { 
    public  int  outputAC220V ( )  { 
        int  output =  220 ; 
        System . out. println ( "输出交流电"  +  output +  "V" ) ; 
        return  output; 
    } 
} 
package  com. shipei ; 
public  interface  DC5  { 
    int  outputDC5V ( ) ; 
} 
package  com. shipei ; 
public  class  PowerAdapter  implements  DC5  { 
    private  AC220  ac220; 
    public  PowerAdapter ( AC220  ac220)  { 
        this . ac220 =  ac220; 
    } 
    public  int  outputDC5V ( )  { 
        int  adapterInput =  ac220. outputAC220V ( ) ; 
        
        int  adapterOutput =  adapterInput /  44 ; 
        System . out. println ( "使用 PowerAdapter 输⼊AC:"  +  adapterInput +  "V 输出DC:"  +  adapterOutput +  "V" ) ; 
        return  adapterOutput; 
    } 
} 
package  com. shipei ; 
public  class  Test  { 
    public  static  void  main ( String [ ]  args)  { 
        DC5  dc5 =  new  PowerAdapter ( new  AC220 ( ) ) ; 
        dc5. outputDC5V ( ) ; 
    } 
} 
package  com. shipei ; 
public  class  PowerAdapter  implements  DC5  { 
    private  AC220  ac220; 
    public  PowerAdapter ( AC220  ac220)  { 
        this . ac220 =  ac220; 
    } 
    
      public  PowerAdapter ( )  { 
    } 
    public  boolean  is ( Object  o)  { 
        
        
        return  AC220 . class . isAssignableFrom ( o. getClass ( ) ) ; 
    } 
    public  int  outputDC5V ( )  { 
        int  adapterInput =  ac220. outputAC220V ( ) ; 
        
        int  adapterOutput =  adapterInput /  44 ; 
        System . out. println ( "使用 PowerAdapter 输⼊AC:"  +  adapterInput +  "V 输出DC:"  +  adapterOutput +  "V" ) ; 
        return  adapterOutput; 
    } 
} 
package  com. shipei ; 
public  class  Test  { 
    public  static  void  main ( String [ ]  args)  { 
        PowerAdapter  powerAdapter =  new  PowerAdapter ( ) ; 
        AC220  ac220 =  new  AC220 ( ) ; 
        boolean  b =  powerAdapter. is ( ac220) ; 
        
        if  ( b ==  true )  { 
            DC5  dc5 =  new  PowerAdapter ( ac220) ; 
            dc5. outputDC5V ( ) ; 
        } 
    } 
} 
package  com. mvc. framework. annotations ; 
import  java. lang. annotation.  * ; 
@Documented 
@Target ( { ElementType . TYPE ,  ElementType . METHOD } ) 
@Retention ( RetentionPolicy . RUNTIME ) 
public  @interface  Security  { 
    String [ ]  value ( )  default  { } ; 
} 
public  class  Handler  { 
    
 
    
    private  String [ ]  Security ; 
    
    
      public  String [ ]  getSecurity ( )  { 
        return  Security ; 
    } 
    public  void  setSecurity ( String [ ]  security)  { 
        Security  =  security; 
    } 
    
    
} 
 if  ( aClass. isAnnotationPresent ( RequestMapping . class ) )  { 
                    
                    String  value =  aClass. getAnnotation ( RequestMapping . class ) . value ( ) ; 
                    
                    if  ( "/" . equals ( value. substring ( 0 ,  1 ) )  ==  false )  { 
                        
                        value =  "/"  +  value; 
                    } 
                    
                    baseUrl +=  value;  
                } 
                
                String [ ]  SecurityAll  =  new  String [ 0 ] ;  
                if ( aClass. isAnnotationPresent ( Security . class ) ) { 
                    
                    SecurityAll  =  aClass. getAnnotation ( Security . class ) . value ( ) ; 
                } 
                        Handler  handler =  new  Handler ( entry. getValue ( ) , method,  Pattern . compile ( url) ) ; 
    
                        String [ ]  Secu  =  SecurityAll ; 
                        if ( method. isAnnotationPresent ( Security . class ) ) { 
                            
                            String [ ]  Seculin  =  method. getAnnotation ( Security . class ) . value ( ) ; 
                            
                            
                            Set < String > =  new  LinkedHashSet < > ( Arrays . asList ( Secu ) ) ; 
                            mergedSet. addAll ( Arrays . asList ( Seculin ) ) ; 
                            
                            Secu  =  mergedSet. toArray ( new  String [ 0 ] ) ; 
                            
                        } 
                        
                        handler. setSecurity ( Secu ) ; 
 String  requestURI =  req. getRequestURI ( ) ; 
        String  contextPath =  req. getContextPath ( ) ; 
        String  substring =  requestURI. substring ( contextPath. length ( ) ,  requestURI. length ( ) ) ; 
Map < String ,  String [ ] >  parameterMap =  req. getParameterMap ( ) ;  
        Set < Map. Entry < String ,  String [ ] >>  entries =  parameterMap. entrySet ( ) ; 
Matcher  matcher =  handler. getPattern ( ) . matcher ( substring) ; 
            
            if  ( ! matcher. matches ( ) )  { 
                continue ; 
            } 
   
            
            String [ ]  security =  handler. getSecurity ( ) ; 
            
            boolean  contains =  false ; 
            
            for  ( Map. Entry < String ,  String [ ] >  param :  entries)  { 
                if  ( "username" . equals ( param. getKey ( ) ) ) { 
                     
                    contains =  Arrays . asList ( security) . contains ( param. getValue ( ) [ 0 ] ) ; 
                } 
            } 
 if  ( contains)  { 
     
                return  handler; 
            } 
public  class  Handler  { 
 
    
    
     public  Handler ( )  { 
    } 
    
    private  String  error; 
    
      public  String  getError ( )  { 
        return  error; 
    } 
    public  void  setError ( String  error)  { 
        this . error =  error; 
    } 
    
    
    
} 
package  com. mvc. framework. servlet ; 
import  com. mvc. framework. annotations.  * ; 
import  com. mvc. framework. config.  ParameterNameExtractor ; 
import  com. mvc. framework. pojo.  Handler ; 
import  com. mvc. framework. util.  UtilGetClassInterfaces ; 
import  org. dom4j.  Document ; 
import  org. dom4j.  Element ; 
import  org. dom4j. io.  SAXReader ; 
import  javax. servlet.  ServletConfig ; 
import  javax. servlet.  ServletException ; 
import  javax. servlet. http.  HttpServlet ; 
import  javax. servlet. http.  HttpServletRequest ; 
import  javax. servlet. http.  HttpServletResponse ; 
import  java. io.  File ; 
import  java. io.  IOException ; 
import  java. io.  InputStream ; 
import  java. lang. reflect.  Field ; 
import  java. lang. reflect.  Method ; 
import  java. lang. reflect.  Parameter ; 
import  java. net.  URLDecoder ; 
import  java. nio. charset.  StandardCharsets ; 
import  java. util.  * ; 
import  java. util. regex.  Matcher ; 
import  java. util. regex.  Pattern ; 
public  class  DispatcherServlet  extends  HttpServlet  { 
    
    
    
    private  static  List < String > =  new  ArrayList < > ( ) ; 
    
    private  static  Map < String ,  Object > =  new  HashMap < > ( ) ; 
    
    private  static  List < String > =  new  ArrayList < > ( ) ; 
    
    private  List < Handler > =  new  ArrayList < > ( ) ; 
    @Override 
    public  void  init ( ServletConfig  config)  { 
        
        
        
        
        String  contextConfigLocation =  config. getInitParameter ( "contextConfigLocation" ) ; 
        
        String  s =  doLoadconfig ( contextConfigLocation) ; 
        
        doScan ( s) ; 
        
        doInstance ( ) ; 
        
        
        doAutoWired ( ) ; 
        
        
        initHandlerMapping ( config) ; 
        
        System . out. println ( "初始化完成...,等待请求与映射匹配了" ) ; 
        
    } 
    
    
    private  void  initHandlerMapping ( ServletConfig  config)  { 
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        if  ( map. isEmpty ( ) )  {  
            return ; 
        } 
        for  ( Map. Entry < String ,  Object > :  map. entrySet ( ) )  { 
            
            Class < ? > =  entry. getValue ( ) . getClass ( ) ; 
            
            
            
            
            
            if  ( aClass. isAnnotationPresent ( Controller . class ) )  { 
                String  baseUrl =  "" ; 
                
                if  ( aClass. isAnnotationPresent ( RequestMapping . class ) )  { 
                    
                    String  value =  aClass. getAnnotation ( RequestMapping . class ) . value ( ) ; 
                    
                    if  ( "/" . equals ( value. substring ( 0 ,  1 ) )  ==  false )  { 
                        
                        value =  "/"  +  value; 
                    } 
                    
                    baseUrl +=  value;  
                } 
                
                
                String [ ]  SecurityAll  =  new  String [ 0 ] ; 
                if  ( aClass. isAnnotationPresent ( Security . class ) )  { 
                    
                    SecurityAll  =  aClass. getAnnotation ( Security . class ) . value ( ) ; 
                } 
                
                
                
                Method [ ]  methods =  aClass. getMethods ( ) ; 
                for  ( int  j =  0 ;  j <  methods. length;  j++ )  { 
                    Method  method =  methods[ j] ; 
                    
                    if  ( method. isAnnotationPresent ( RequestMapping . class ) )  { 
                        RequestMapping  annotation =  method. getAnnotation ( RequestMapping . class ) ; 
                        String  value =  annotation. value ( ) ;  
                        
                        if  ( "/" . equals ( value. substring ( 0 ,  1 ) )  ==  false )  { 
                            
                            value =  "/"  +  value; 
                        } 
                        
                        String  url =  baseUrl; 
                        url +=  value; 
                        
                        Handler  handler =  new  Handler ( entry. getValue ( ) ,  method,  Pattern . compile ( url) ) ; 
                        
                        String [ ]  Secu  =  SecurityAll ; 
                        if  ( method. isAnnotationPresent ( Security . class ) )  { 
                            
                            String [ ]  Seculin  =  method. getAnnotation ( Security . class ) . value ( ) ; 
                            
                            
                            Set < String > =  new  LinkedHashSet < > ( Arrays . asList ( Secu ) ) ; 
                            mergedSet. addAll ( Arrays . asList ( Seculin ) ) ; 
                            
                            Secu  =  mergedSet. toArray ( new  String [ 0 ] ) ; 
                        } 
                        
                        handler. setSecurity ( Secu ) ; 
                        
                        
                        
                        Map < String ,  String > =  null ; 
                        try  { 
                            String  ba =  aClass. getName ( ) . replace ( '.' ,  '/' )  +  ".class" ; 
                            
                            prmap =  ParameterNameExtractor . getParameterNames ( config. getServletContext ( ) . getRealPath ( "/" )  +  "WEB-INF\\classes\\"  +  ba,  method. getName ( ) ) ; 
                        }  catch  ( Exception  e)  { 
                            e. printStackTrace ( ) ; 
                        } 
                        Parameter [ ]  parameters =  method. getParameters ( ) ; 
                        for  ( int  i =  0 ;  i <  parameters. length;  i++ )  { 
                            Parameter  parameter =  parameters[ i] ; 
                            
                            if  ( parameter. getType ( )  ==  HttpServletRequest . class  ||  parameter. getType ( )  ==  HttpServletResponse . class )  { 
                                
                                handler. getParamIndexMapping ( ) . put ( parameter. getType ( ) . getSimpleName ( ) ,  i) ; 
                            }  else  { 
                                
                                
                                handler. getParamIndexMapping ( ) . put ( prmap. get ( i) ,  i) ; 
                            } 
                        } 
                        
                        handlerMapping. add ( handler) ; 
                        
                        
                    } 
                } 
            } 
        } 
    } 
    
    private  void  doAutoWired ( )  { 
        if  ( map. isEmpty ( ) )  {  
            return ; 
        } 
        
        for  ( Map. Entry < String ,  Object > :  map. entrySet ( ) )  { 
            try  { 
                
                doObjectDependancy ( entry. getValue ( ) ) ; 
            }  catch  ( Exception  e)  { 
                e. printStackTrace ( ) ; 
            } 
        } 
    } 
    
    private  static  void  doObjectDependancy ( Object  object)  { 
        
        Field [ ]  declaredFields =  object. getClass ( ) . getDeclaredFields ( ) ; 
        
        if  ( declaredFields ==  null  ||  declaredFields. length ==  0 )  { 
            return ; 
        } 
        for  ( int  i =  0 ;  i <  declaredFields. length;  i++ )  { 
            
            
            Field  declaredField =  declaredFields[ i] ; 
            
            if  ( ! declaredField. isAnnotationPresent ( Autowired . class ) )  { 
                continue ; 
            } 
            
            
            
            
            
            
            
            
            
            if  ( fieldsAlreayProcessed. contains ( object. getClass ( ) . getName ( )  +  "."  +  declaredField. getName ( ) ) )  { 
                continue ; 
            } 
            
            
            Object  dependObject =  null ; 
            Autowired  annotation =  declaredField. getAnnotation ( Autowired . class ) ; 
            String  value =  annotation. value ( ) ; 
            if  ( "" . equals ( value. trim ( ) ) )  {  
                
                
                
                dependObject =  map. get ( declaredField. getType ( ) . getName ( ) ) ; 
                
                
                if  ( dependObject ==  null )  { 
                    
                    dependObject =  map. get ( lowerFirst ( declaredField. getType ( ) . getSimpleName ( ) ) ) ; 
                } 
            }  else  { 
                
                dependObject =  map. get ( value +  declaredField. getType ( ) . getName ( ) ) ; 
            } 
            
            
            
            
            
            
            
            fieldsAlreayProcessed. add ( object. getClass ( ) . getName ( )  +  "."  +  declaredField. getName ( ) ) ; 
            
            if  ( dependObject !=  null )  { 
                doObjectDependancy ( dependObject) ; 
            } 
            
            
            
            declaredField. setAccessible ( true ) ; 
            
            try  { 
                declaredField. set ( object,  dependObject) ; 
            }  catch  ( Exception  e)  { 
                e. printStackTrace ( ) ; 
            } 
        } 
    } 
    
    private  void  doInstance ( )  { 
        
        if  ( classNames. size ( )  ==  0 )  return ; 
        if  ( classNames. size ( )  <=  0 )  return ;  
        try  { 
            for  ( int  i =  0 ;  i <  classNames. size ( ) ;  i++ )  { 
                
                String  className =  classNames. get ( i) ; 
                
                Class < ? > =  Class . forName ( className) ; 
                
                
                
                if  ( aClass. isAnnotationPresent ( Controller . class ) )  { 
                    
                    
                    
                    String  simpleName =  aClass. getSimpleName ( ) ; 
                    String  s =  lowerFirst ( simpleName) ; 
                    
                    
                    Object  o =  aClass. newInstance ( ) ; 
                    map. put ( s,  o) ; 
                } 
                
                
                
                if  ( aClass. isAnnotationPresent ( Service . class ) )  { 
                    String  beanName =  aClass. getAnnotation ( Service . class ) . value ( ) ; 
                    
                    Object  o =  aClass. newInstance ( ) ; 
                    int  ju =  0 ; 
                    if  ( "" . equals ( beanName. trim ( ) ) )  { 
                        
                        
                        beanName =  lowerFirst ( aClass. getSimpleName ( ) ) ; 
                    }  else  { 
                        ju =  1 ; 
                    } 
                    
                    
                    
                    if  ( ju ==  1 )  { 
                        UtilGetClassInterfaces . getkeyClass ( beanName,  aClass,  map,  o) ; 
                    }  else  { 
                        map. put ( beanName,  o) ; 
                    } 
                    
                    
                    
                    Class < ? > [ ]  interfaces =  aClass. getInterfaces ( ) ; 
                    if  ( interfaces !=  null  &&  interfaces. length >  0 )  { 
                        for  ( int  j =  0 ;  j <  interfaces. length;  j++ )  { 
                            
                            
                            Class < ? > =  interfaces[ j] ; 
                            
                            map. put ( anInterface. getName ( ) ,  aClass. newInstance ( ) ) ; 
                            
                            
                            
                        } 
                    } 
                } 
            } 
        }  catch  ( Exception  e)  { 
            e. printStackTrace ( ) ; 
        } 
    } 
    
    private  static  String  lowerFirst ( String  str)  { 
        char [ ]  chars =  str. toCharArray ( ) ; 
        if  ( 'A'  <=  chars[ 0 ]  &&  chars[ 0 ]  <=  'Z' )  { 
            chars[ 0 ]  +=  32 ;  
        } 
        return  String . valueOf ( chars) ;  
    } 
    
    private  void  doScan ( String  scanPackage)  { 
        try  { 
            
            String  scanPackagePath =  Thread . currentThread ( ) . getContextClassLoader ( ) . getResource ( "" ) . getPath ( )  +  scanPackage. replaceAll ( "\\." ,  "/" ) ; 
            scanPackagePath =  URLDecoder . decode ( scanPackagePath,  StandardCharsets . UTF_8 . toString ( ) ) ; 
            File  pack =  new  File ( scanPackagePath) ;  
            File [ ]  files =  pack. listFiles ( ) ; 
            for  ( File  file :  files)  { 
                
                if  ( file. isDirectory ( ) )  { 
                    
                    doScan ( scanPackage +  "."  +  file. getName ( ) ) ; 
                    
                    continue ; 
                } 
                
                if  ( file. getName ( ) . endsWith ( ".class" ) )  { 
                    
                    String  className =  scanPackage +  "."  +  file. getName ( ) . replaceAll ( ".class" ,  "" ) ; 
                    classNames. add ( className) ;  
                } 
            } 
        }  catch  ( Exception  e)  { 
            e. printStackTrace ( ) ; 
        } 
    } 
    
    private  String  doLoadconfig ( String  contextConfigLocation)  { 
        
        InputStream  resourceAsStream =  DispatcherServlet . class . getClassLoader ( ) . getResourceAsStream ( contextConfigLocation) ; 
        
        
        SAXReader  saxReader =  new  SAXReader ( ) ; 
        try  { 
            
            Document  document =  saxReader. read ( resourceAsStream) ; 
            
            Element  rootElement =  document. getRootElement ( ) ; 
            
            Element  element =  ( Element )  rootElement. selectSingleNode ( "//component-scan" ) ; 
            
            String  attribute =  element. attributeValue ( "base-package" ) ; 
            return  attribute; 
        }  catch  ( Exception  e)  { 
            e. printStackTrace ( ) ; 
        } 
        return  "" ; 
    } 
    @Override 
    protected  void  doGet ( HttpServletRequest  req,  HttpServletResponse  resp)  throws  ServletException ,  IOException  { 
        doPost ( req,  resp) ; 
    } 
    @Override 
    protected  void  doPost ( HttpServletRequest  req,  HttpServletResponse  resp)  throws  ServletException ,  IOException  { 
        Handler  handler =  getHandler ( req) ; 
        if  ( handler ==  null )  { 
            resp. getWriter ( ) . write ( "404 not found" ) ; 
            return ; 
        } 
        
        
        
        Class < ? > [ ]  parameterTypes =  handler. getMethod ( ) . getParameterTypes ( ) ;  
        
        
        Object [ ]  objects =  new  Object [ parameterTypes. length] ; 
        
        int [ ]  ii =  new  int [ parameterTypes. length] ; 
        
        Map < String ,  String [ ] >  parameterMap =  req. getParameterMap ( ) ;  
        Set < Map. Entry < String ,  String [ ] >>  entries =  parameterMap. entrySet ( ) ; 
        
        for  ( Map. Entry < String ,  String [ ] >  param :  entries)  { 
            String  value =  "" ; 
            
            for  ( int  i =  0 ;  i <  param. getValue ( ) . length;  i++ )  { 
                if  ( i >=  param. getValue ( ) . length -  1 )  { 
                    value =  param. getValue ( ) [ i] ; 
                    continue ; 
                } 
                value =  param. getValue ( ) [ i]  +  "," ; 
            } 
            
            
            
            
            
            
            
            if  ( ! handler. getParamIndexMapping ( ) . containsKey ( param. getKey ( ) ) )  { 
                
                
                continue ; 
            } 
            
            Integer  integer =  handler. getParamIndexMapping ( ) . get ( param. getKey ( ) ) ; 
            
            
            if  ( "String" . equals ( parameterTypes[ integer] . getSimpleName ( ) ) )  { 
                objects[ integer]  =  value; 
            } 
            
            if  ( "Integer" . equals ( parameterTypes[ integer] . getSimpleName ( ) )  ||  "int" . equals ( parameterTypes[ integer] . getSimpleName ( ) ) )  { 
                
                value =  value. split ( "," ) [ 0 ] ; 
                Integer  i =  null ; 
                try  { 
                    i =  Integer . parseInt ( value) ; 
                }  catch  ( Exception  e)  { 
                    e. printStackTrace ( ) ; 
                    throw  new  RuntimeException ( "String转换Integet报错,参数名称是:"  +  param. getKey ( ) ) ; 
                } 
                objects[ integer]  =  i; 
            } 
            
            
            ii[ integer]  =  1 ; 
        } 
        
        
        
        
        Integer  integer =  handler. getParamIndexMapping ( ) . get ( HttpServletRequest . class . getSimpleName ( ) ) ; 
        objects[ integer]  =  req; 
        ii[ integer]  =  1 ; 
        integer =  handler. getParamIndexMapping ( ) . get ( HttpServletResponse . class . getSimpleName ( ) ) ; 
        objects[ integer]  =  resp; 
        ii[ integer]  =  1 ; 
        
        
        for  ( int  i =  0 ;  i <  ii. length;  i++ )  { 
            if  ( ii[ i]  ==  0 )  { 
                if  ( "int" . equals ( parameterTypes[ i] . getSimpleName ( ) ) )  { 
                    
                    objects[ i]  =  0 ; 
                } 
                
            } 
        } 
        
        
        
        
        try  { 
            handler. getMethod ( ) . invoke ( handler. getController ( ) ,  objects) ;  
        }  catch  ( Exception  e)  { 
            e. printStackTrace ( ) ; 
        } 
        
        
        
    } 
    private  Handler  getHandler ( HttpServletRequest  req)  { 
        if  ( handlerMapping. isEmpty ( ) )  { 
            return  null ; 
        } 
        String  requestURI =  req. getRequestURI ( ) ; 
        String  contextPath =  req. getContextPath ( ) ; 
        String  substring =  requestURI. substring ( contextPath. length ( ) ,  requestURI. length ( ) ) ; 
        Map < String ,  String [ ] >  parameterMap =  req. getParameterMap ( ) ;  
        Set < Map. Entry < String ,  String [ ] >>  entries =  parameterMap. entrySet ( ) ; 
        
        boolean  ur =  false ; 
        
        boolean  contains =  false ; 
        
        String  pe =  "" ; 
        for  ( Handler  handler :  handlerMapping)  { 
            
            
            
            
            Matcher  matcher =  handler. getPattern ( ) . matcher ( substring) ; 
            
            if  ( ! matcher. matches ( ) )  { 
                continue ; 
            } 
            ur =  true ; 
            
            
            String [ ]  security =  handler. getSecurity ( ) ; 
            
            for  ( Map. Entry < String ,  String [ ] >  param :  entries)  { 
                if  ( "username" . equals ( param. getKey ( ) ) )  { 
                    pe =  param. getValue ( ) [ 0 ] ; 
                    
                    contains =  Arrays . asList ( security) . contains ( pe) ; 
                } 
            } 
            if  ( contains)  { 
                return  handler; 
            } 
        } 
        Handler  handler =  new  Handler ( ) ; 
        if  ( ! ur)  { 
            handler. setError ( "路径错误" ) ; 
            return  handler; 
        } 
        if  ( ! contains)  { 
            handler. setError ( pe +  "没有访问权限" ) ; 
            return  handler; 
        } 
        
        return  null ; 
    } 
} 
Handler  handler =  getHandler ( req) ; 
        if  ( handler ==  null )  { 
            resp. getWriter ( ) . write ( "404 not found" ) ; 
            return ; 
        } 
Handler  handler =  getHandler ( req) ; 
        if  ( handler. getError ( )  !=  null )  { 
            resp. setContentType ( "text/html;charset=UTF-8" ) ; 
            resp. getWriter ( ) . write ( handler. getError ( ) ) ; 
            return ; 
        }