Springmvc--handleradapter

Source: Internet
Author: User

Three methods are defined in the Handleradapter interface:

(1) Boolean supports (Object handler); Determine if the incoming handler is supported

(2) Modelandview handle (HttpServletRequest request, httpservletresponse response, Object handler) used to process requests using handler

(3) long getlastmodified (HttpServletRequest request, Object handler); The last-modified value used to obtain the data.

The interface source code is as follows:

Public interface Handleradapter {  
  
    Boolean supports (Object handler);  
  
    Modelandview handle (HttpServletRequest request, httpservletresponse response, Object handler) throws Exception;  
  
    Long getlastmodified (httpservletrequest request, Object handler);  
  
}  
The execution of the Handleradapter is performed in the Dispatcherservlet Dodispatch, and the execution process is as follows:

protected void Dodispatch (HttpServletRequest request, httpservletresponse response) throws Exception {  
          
        .....  
  
        try {  
              
            try {  
                  
                //get the appropriate Handleradapter implementation class  
                Handleradapter ha = Gethandleradapter ( Mappedhandler.gethandler ());  
                  
            ........  
                  
                if (Isget | | "HEAD". Equals (method)) {  
                    Long lastmodified = ha.getlastmodified (Request, Mappedhandler.gethandler ());  
                      
                }  
            ........  
                Perform a true request operation  
                mv = Ha.handle (processedrequest, Response, Mappedhandler.gethandler ());  
  
        ........  
    }  
The gethandleradapter operation is to choose the appropriate handleradapter to execute, the adapter pattern in design mode, the content in Handleradapters is all the Handleradapter implementation class.

Protected Handleradapter Gethandleradapter (Object handler) throws Servletexception {for  
        (Handleradapter ha: This.handleradapters) {  
            if (logger.istraceenabled ()) {  
                Logger.trace ("Testing handler adapter [" + Ha + "]");  
            }  
            if (Ha.supports (handler)) {  
                return ha;  
            }  
        }  
        throw new Servletexception ("No Adapter for Handler [" + Handler +  
                "]: The Dispatcherservlet configuration needs to Inc Lude a handleradapter that supports this handler ");  
    }  

This completes the actual invocation of the handler, and the final call procedure is to return a Modelandview object.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.