Learning materials : Open wave 《 Follow me SpringMVC.pdf》

as everyone knows ,springMVC It's quite common web frame , Usually Integration spring Use . Let's get out of here spring, Simply right springMVC Let's summarize .

Concept

HandlerMapping: Processor mapping , On request URL Mapping to specific processors ( If there are interceptors, there are also interceptors , Will Handler And multiple HandlerInterceptor Encapsulated in the HandlerExecutionChain object )

HandlerAdapter: Processor adapter , Adapting to different types of processors , Such as Controller、AbstractController etc.

Handler: processor , That is, the development of Controller

ModeAndView: Models and views , In the future, it will be rendered as a concrete view

ViewResolver: view resolver , Convert logical view name to physical view

View: View

flow chart

Analysis of source code ( Excerpt from DispatcherServlet The source code section )

because springMVC The configuration itself is the last one servlet, So tracking code doService()=>doDispatcher(), The core code is as follows , The Chinese notes were added by themselves

protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
HttpServletRequest processedRequest = request;
HandlerExecutionChain mappedHandler = null;
boolean multipartRequestParsed = false; WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request); try {
ModelAndView mv = null;
Exception dispatchException = null; try {
// Processing data of file upload type , Use MultipartResolver analysis
processedRequest = checkMultipart(request);
multipartRequestParsed = (processedRequest != request); // Use HandlerMapping mapping , Will a Handler And multiple HandlerInterceptor Encapsulated in the HandlerExecutionChain object
mappedHandler = getHandler(processedRequest);
if (mappedHandler == null || mappedHandler.getHandler() == null) {
noHandlerFound(processedRequest, response);
return;
} // according to Handler Get the right Handler Adapter
HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler()); // Process last-modified header, if supported by the handler.
String method = request.getMethod();
boolean isGet = "GET".equals(method);
if (isGet || "HEAD".equals(method)) {
long lastModified = ha.getLastModified(request, mappedHandler.getHandler());
if (logger.isDebugEnabled()) {
logger.debug("Last-Modified value for [" + getRequestUri(request) + "] is: " + lastModified);
}
if (new ServletWebRequest(request, response).checkNotModified(lastModified) && isGet) {
return;
}
} /*
* To invoke the interceptor preHandle(), return true Proceed to the next interceptor or processor , return false Interrupt the process and execute the successful interceptor afterCompletion().
*/
if (!mappedHandler.applyPreHandle(processedRequest, response)) {
return;
} // Use HandlerAdapter perform Handler And back to ModeAndView
mv = ha.handle(processedRequest, response, mappedHandler.getHandler()); if (asyncManager.isConcurrentHandlingStarted()) {
return;
} applyDefaultViewName(processedRequest, mv);
// To invoke the interceptor postHandle() Method
mappedHandler.applyPostHandle(processedRequest, response, mv);
}
catch (Exception ex) {
dispatchException = ex;
}
catch (Throwable err) {
// As of 4.3, we're processing Errors thrown from handler methods as well,
// making them available for @ExceptionHandler methods and other scenarios.
dispatchException = new NestedServletException("Handler dispatch failed", err);
}
// Processing forwarding results , contain ModeAndView View resolution for , After the view is parsed, the interceptor is called afterCompletion() function
processDispatchResult(processedRequest, response, mappedHandler, mv, dispatchException);
}
catch (Exception ex) {
triggerAfterCompletion(processedRequest, response, mappedHandler, ex);
}
catch (Throwable err) {
triggerAfterCompletion(processedRequest, response, mappedHandler,
new NestedServletException("Handler processing failed", err));
}
finally {
if (asyncManager.isConcurrentHandlingStarted()) {
// Instead of postHandle and afterCompletion
if (mappedHandler != null) {
mappedHandler.applyAfterConcurrentHandlingStarted(processedRequest, response);
}
}
else {
// Clean up any resources used by a multipart request.
if (multipartRequestParsed) {
cleanupMultipart(processedRequest);
}
}
}
}

SpringMVC Study ( One )—— Concept 、 flow chart 、 Source code analysis of more related articles

  1. Flink Source code reading ( One )——Flink on Yarn Of Per-job Pattern source code analysis

    One . Preface I feel like learning Flink In fact, the most important blog post that should not be missed is Flink Community blog series , The articles in it will not disappoint people . Strong Amway :https://ververica.cn/developers-resource ...

  2. django-jwt token Check the source code analysis

    One . jwt token Check the source code analysis 1.1 Preface Before using jwt Issued token, The header contains the encryption method . Whether there is a signature, etc , And the payload contains the user name . With the head of the household key . Expiration time and other information , The final signature also uses the digest algorithm ...

  3. 0002 - Spring MVC Interceptor source code analysis : Interceptor loading and executing

    1. summary Spring MVC Interceptors in (Interceptor) Be similar to Servlet Filter in (Filter), It is mainly used to intercept user requests and handle them accordingly . For example, the interceptor can verify the permission . The day on which the requested information is recorded ...

  4. spring ioc Analysis of source code

    ClassPathXmlApplicationContext First of all, let's start from normal spring frequently-used ClassPathXmlApplicationContext Start parsing ApplicationCont ...

  5. AFNetworking Analysis of source code

    AFNetworking It is basically the standard configuration of network request Library in Apple development , It's a lightweight web Library , Specifically for iOS and OS X Network application design of , With modular architecture and rich APIs Interface , Powerful and easy to use , Apple's app developers ...

  6. OpenStack And Glance Analysis of source code

    Glance brief introduction OpenStack The mirror server is a set of virtual machine image discovery . register . retrieval . glance Architecture diagram : Glance Source structure : glance/api: It is mainly responsible for receiving and responding to image management commands Restful request , ...

  7. ElementUI Analysis of source code —— Source structure

    ElementUI As the most widely used Vue PC End component library , quite a lot Vue The architecture of component library is reference ElementUI It's done . As a front end with dreams ( Salted fish ), Of course, we need to study this relatively mature architecture . ...

  8. Analysis of source code XXL-JOB The registration and execution process of

    One , Preface XXL-JOB Is an excellent domestic open source distributed task scheduling platform , He has his own dispatch registry , Rich scheduling and blocking strategies are provided , These are all visual operations , It's very convenient to use . Because it is made in China , So it's faster to start ...

  9. DRF And APIView Analysis of source code

    One . install djangorestframework There are three ways to install , Be careful , The module is called djangorestframework. Mode one :pip3 install djangorestframework ...

Random recommendation

  1. TortoiseGit Use and operation

    Use Git Sometimes orders are really inconvenient , In particular, you have to enter the password every time , If configured SSH The way , It's really troublesome .( Of course , You have to use Windows Artifact has a convenient and friendly client graphical interface !!!) 1. Cloning project open ...

  2. install win7 32 The solution to the problem of bit system

    The computer unexpectedly rebooted or encountered an error .Windows Installation cannot continue . If you want to install Windows, Please click on the “ determine ” Restart the computer , Then restart the installation ”. http://www.baidusoso.net/      ...

  3. shell And sort

    turn http://www.cnblogs.com/51linux/archive/2012/05/23/2515299.html) sort Is in Linux A very common command in , Tube sequencing , Concentrate , Five minutes ...

  4. Talking about Java Memory leak

    One . introduction Wait a minute …… Tired

  5. [01] Preparation - Sitecore Installment

    Sitecore CMS It's a content management system business software , Its underlying platform relies on Microsoft .net technology . Because a recent project adopted this platform , So I have access to this product . Although we have been in touch with this product for some time , But I always feel that this product is lack of ...

  6. javascript middle preventDefault And stopPropagation Role Introduction

    preventDefault What is the role of the method , it ? We know , for example ,<a href="http://www.baidu.com"> Baidu </a>, This is a html ...

  7. 【BZOJ4566】 Find the same character ( Postfix automaton )

    [BZOJ4566] Find the same character ( Postfix automaton ) Topic BZOJ Answer key See multiple strings ,\(SA\) Connect them \(SAM???\) Single string automata Then other strings match For a string finished \(SAM\) after The other string is in \ ...

  8. Web Front end tutorial 2-CSS course

    Catalog 1. CSS Basic grammar 1.1. CSS The basic definition 1.2. CSS Layout properties 1.3. CSS Common properties of text 2.CSS Selectors 2.1. tag chooser 2.2. id Selectors 2.3. Class selectors 2.4. ...

  9. gdb Debug usage

    Catalog One .gdb Function introduction Two .gdb Use preconditions : Add... At compile time debug Information . 3、 ... and .gdb The most common usages : 1.gdb Start of , Loader : 2. Debugging a running program : 3. check core: Four .gdb Common life ...

  10. redis Cache breakdown Watch a series of becoming a master 3

    What is cache breakdown Before we talk about cache breakdown , Let's first recall the logic of loading data from the cache , As shown in the figure below therefore , If the hacker deliberately queries a data that does not exist in the cache every time , This causes every request to be queried in the storage layer , In this way, the cache is meaningless . If ...