回覆列表
  • 1 # 大國師魂系列

    springboot引數解析原理就是引數變數變成對應的固定值。

    public class DispatcherServlet{

    protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {

    mappedHandler = this.getHandler(processedRequest);

    if (mappedHandler == null) {

    this.noHandlerFound(processedRequest, response);

    return;

    }

    //繼續向下

    // Determine handler adapter for the current request.

    HandlerAdapter ha = 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);

    }

    }。這就是HandlerAdapter的作用,在getHandler方法確定好控制器和對應的方法後(執行鏈),getHandlerAdapter就會來幫我們為當前的handler找一個adapter然後我們透過該介面卡,就能夠將請求的連結所帶的引數給適配上。

  • 中秋節和大豐收的關聯?
  • 塗料粘在衣服上要怎麼洗掉?