• SpringMVC中的handler是什么?什么类型?


    从DispatcherServlet中开始找,首先要知道hander是Object类型,一开始是一个类的全限定名。

    HandlerExecutionChain handler = hm.getHandler(request);
    //是由HandlerMapping得到的: HandlerMapping.getHandler(HttpServletRequest request)
    handler = getApplicationContext().getBean(handlerName);
    //在HandlerMapping的getHandler中: AbstractHandlerMapping.getHandler(HttpServletRequest request)

     而if(handler instanceof String) String handlerName = (String) handler; 应该是一个全限定名。

     得到handler、  再下来得到HandlerExecutionChain,就可以返回到DispatcherServlet了

    HandlerExecutionChain executionChain = getHandlerExecutionChain(handler, request);
    
    HandlerExecutionChain的构造方法:
    public HandlerExecutionChain(Object handler) {
    		this(handler, (HandlerInterceptor[]) null);
    	}
    

     到这里就可以return HandlerExecutionChain了。

    还没弄清楚String handler是哪里冒出来的。

    public final HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
    		Object handler = getHandlerInternal(request);  
    //就是这里拿到的,在本类中是abstract方法

        AbstractUrlHandlerMapping是一个实现getHandlerInternal(request)方法的abstract类。
          且返回类型Object,像是我们要找的.

    /**
    	 * Look up a handler for the URL path of the given request.
    	 * @param request current HTTP request
    	 * @return the handler instance, or {@code null} if none found
          */

     下面是AbstractUrlHandlerMapping得到handler的方法实现:

    protected Object getHandlerInternal(HttpServletRequest request) throws Exception {
        // 这个lookupPath应该叫做path或者urlPath。写出来为了易读。
            String lookupPath = getUrlPathHelper().getLookupPathForRequest(request); 
            Object handler = lookupHandler(lookupPath, request);  //lookup有查表的意思。
            if (handler == null) {
                // We need to care for the default handler directly, since we need to
                // expose the PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE for it as well.
                Object rawHandler = null;
                if ("/".equals(lookupPath)) {
                ……

    忽然发现上面的都是废话,我就想知道怎么从request的url中得到handler的。

  • 相关阅读:
    streamsets docker 安装试用
    使用graphql-code-generator 生成graphql 代码
    ORA-12537:TNS:connectionclosed错误处理过程
    解决Oracle 11gR2 空闲连接过多,导致连接数满的问题
    ORACLE定期清理INACTIVE会话
    Oracle session active 和 inactive 状态 说明
    如何查看数据库软件共创建了多少个库(实例)
    某表空间增长很快,但找不到是哪一个表造成的
    Oracle用户被锁定解决方法
    Oracle的sqlnet.ora文件配置
  • 原文地址:https://www.cnblogs.com/wtjqs/p/11753513.html
Copyright © 2020-2023  润新知