SSM

SpringMVC(4): DispatcherServlet前

2019-11-25  本文已影响0人  奇点一氪

本文通过前端控制器源码分析springmvc执行过程

protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
        HttpServletRequest processedRequest = request;
        HandlerExecutionChain mappedHandler = null;
        boolean multipartRequestParsed = false;
    
         。。。。。
}
// Determine handler for the current request.
mappedHandler = getHandler(processedRequest);

/**
     * Return the HandlerExecutionChain for this request.
     * <p>Tries all handler mappings in order.
     * @param request current HTTP request
     * @return the HandlerExecutionChain, or {@code null} if no handler could be found
     */
    protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
        for (HandlerMapping hm : this.handlerMappings) {
            if (logger.isTraceEnabled()) {
                logger.trace(
                        "Testing handler map [" + hm + "] in DispatcherServlet with name '" + getServletName() + "'");
            }
            HandlerExecutionChain handler = hm.getHandler(request);
            if (handler != null) {
                return handler;
            }
        }
        return null;
    }

// Actually invoke the handler.
mv = ha.handle(processedRequest, response, mappedHandler.getHandler());
// We need to resolve the view name.
view = resolveViewName(mv.getViewName(), mv.getModelInternal(), locale, request);

调用view的渲染方法,将model数据填充到request域

在render方法中,调用View接口的render方法

view.render(mv.getModelInternal(), request, response);
上一篇下一篇

猜你喜欢

热点阅读