后端——框架——视图层框架——spring_mvc——《官网》阅读笔记——第一章节3(核心对象,简述)

  本小节对应1.1.2中的内容,它简述Spring MVC的核心对象。

  HandlerMapping:Map a request to a handler along with a list of interceptors for pre- and post-processing. The mapping is based on some criteria, the details of which vary by HandlerMapping implementation.The two main HandlerMapping

implementations are RequestMappingHandlerMapping (which supports @RequestMapping annotated methods) and SimpleUrlHandlerMapping (which maintains explicit registrations of URI path patterns to handlers)

    HandlerMapping的主要作用是建立请求与处理器的关联关系。在Servlet中是通过servlet-name作为桥梁,将url-pattern和servlet类关联起来。

    HandlerMapping的主要实现类有两个RequestMappingHandlerMapping,SimpleUrlHandlerMapping。RequestMapping主要处理@RequestMapping注解标注的方法。

  HandlerAdapterHelp the DispatcherServlet to invoke a handler mapped to a request, regardless of how the handler is actually invoked. For example, invoking an annotated controller requires resolving annotations. The main purpose of a HandlerAdapter is to shield the DispatcherServlet from such details

处理handler方法的具体调用,从DispatcherServlet中的doService--->doDispatch方法的部分源码如下:

// Determine handler adapter for the current request.
HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler());

// 处理 last-modified 请求头, 
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;
}
// Actually invoke the handler.
mv = ha.handle(processedRequest, response, mappedHandler.getHandler());

  

ViewResolver :Resolve logical String -based view names returned from a handler to an actual View with which to render to the response

视图解析器,根据视图的名称生成具体的视图类型,并生成响应。返回值必须是字符串。

 

LocaleResolverResolve the Locale a client is using and possibly their time zone, in order to be able to other internationalized views

获取客户端的国际化信息。例如时区,语言,国家等。

 

ThemeResolver:Resolve themes your web application can use — for example, to other personalized layouts(略 )

 

MultipartResolver:Abstraction for parsing a multi-part request (for example, browser form file upload) with the help of some multipart parsing library

处理multi-part类型的请求,它没有默认值,若想实现上传文件时,需要自己配置。

 

FlashMapManager Store and retrieve the “input” and the “output” FlashMap that can be used to pass attributes from one request to another, usually across a redirect

目前未使用过,(本文略)。

原文地址:https://www.cnblogs.com/rain144576/p/12903088.html