springMVC简单来说就是一个Servlet
org.springframework.web.servlet.DispatcherServlet
一切代码都是围绕protected void doDispatch(HttpServletRequest request, HttpServletResponse response)
展开
代码机构
-
org.springframework.web.servlet.HandlerMapping
- org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping controller
- org.springframework.web.method.HandlerMethod controller-method
- org.springframework.web.servlet.handler.SimpleUrlHandlerMapping
- org.springframework.web.HttpRequestHandler
- org.springframework.web.servlet.resource.ResourceHttpRequestHandler
- org.springframework.web.HttpRequestHandler
- org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping controller
-
org.springframework.web.servlet.HandlerAdapter
- org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
- org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter
首先会有很多个org.springframework.web.servlet.HandlerMapping
1 | public interface HandlerMapping { |
Controller会抽象成一个org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
Method会抽象成org.springframework.web.method.HandlerMethod
储存在
org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.MappingRegistry
静态资源
1 | <mvc:resources mapping="/resources/**" location="/public, classpath:/static/" cache-period="31556926" /> |
这种静态资源会抽象成org.springframework.web.servlet.handler.SimpleUrlHandlerMapping
里面静态资源路劲抽象成
org.springframework.web.HttpRequestHandler
1 | public interface HttpRequestHandler { |
1 | public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping implements MatchableHandlerMapping { |
路径匹配
1 | new AntPathMatcher(String pattern, String path).match(); |