Spring mvc中的HandlerMapping接口以及HandlerAdapter 接口

来源:互联网 发布:避雷针高度计算软件 编辑:程序博客网 时间:2024/04/29 08:43

HandlerMapping接口的实现(只举了我认识的几个) : 

    BeanNameUrlHandlerMapping :通过对比url和bean的name找到对应的对象 
    SimpleUrlHandlerMapping :也是直接配置url和对应bean,比BeanNameUrlHandlerMapping功能更多 
    DefaultAnnotationHandlerMapping : 主要是针对注解配置@RequestMapping的,已过时 
    RequestMappingHandlerMapping :取代了上面一个 

HandlerAdapter 接口实现: 

    HttpRequestHandlerAdapter : 要求handler实现HttpRequestHandler接口,该接口的方法为                                                             void handleRequest(HttpServletRequest request, HttpServletResponse response)也就是  handler必须有一个handleRequest方法 

    SimpleControllerHandlerAdapter:要求handler实现Controller接口,该接口的方法为ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response),也就是本工程采用的 

    AnnotationMethodHandlerAdapter :和上面的DefaultAnnotationHandlerMapping配对使用的,也已过时 

    RequestMappingHandlerAdapter : 和上面的RequestMappingHandlerMapping配对使用,针对@RequestMapping 

先简单的说下这个工程的流程,访问http://localhost:8080/index首先由DispatcherServlet进行转发,通过BeanNameUrlHandlerMapping(含有 /index->HomeAction的配置),找到了HomeAction,然后再拿HomeAction和每个adapter进行适配,由于HomeAction实现了Controller接口,所以最终会有SimpleControllerHandlerAdapter来完成对HomeAction的handleRequest方法的调度。然后就顺利的执行了我们想要的方法,后面的内容不在本节中说明。 



HandlerMapping接口——》找东西

HandlerAdapter 接口——》方法的调度


0 0