3 非注解的处理器映射器和适配器

  3.1 非注解的处理器映射器

    3.1.1 HandlerMapping处理器映射器

HandlerMapping 负责根据request请求找到对应的Handler处理器及Interceptor拦截器,将它们封装在HandlerExecutionChain 对象中给前端控制器返回。

      3.1.1.1 BeanNameUrlHandlerMapping

BeanNameUrl处理器映射器,根据请求的url与spring容器中定义的bean的name进行匹配,从而从spring容器中找到bean实例。

处理器映射器:

org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping

<!—beanName Url映射器 -->
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>

      3.1.1.2 SimpleUrlHandlerMapping

simpleUrlHandlerMapping是BeanNameUrlHandlerMapping的增强版本,它可以将url和处理器bean的id进行统一映射配置。

    <!—简单url映射 -->
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/items1.action">controller的bean id</prop>
<prop key="/items2.action">controller的bean id</prop>
</props>
</property>
</bean>

另一个映射器:可以将url和handler集中配置

org.springframework.web.servlet.handler.SimpleUrlHandlerMapping

测试:

http://localhost:8080/springmvcfirst1217/queryItems.action

http://localhost:8080/springmvcfirst1217/queryItems1.action

http://localhost:8080/springmvcfirst1217/queryItems2.action

都可以访问

多个映射器可以并存,前端控制器判断url能让哪些映射器映射,就让正确的映射器处理。

  3.2 非注解的处理器适配器

    3.2.1 HandlerAdapter处理器适配器

HandlerAdapter会根据适配器接口对后端控制器进行包装(适配),包装后即可对处理器进行执行,通过扩展处理器适配器可以执行多种类型的处理器,这里使用了适配器设计模式。

      3.2.1.1 SimpleControllerHandlerAdapter

SimpleControllerHandlerAdapter简单控制器处理器适配器,所有实现了org.springframework.web.servlet.mvc.Controller 接口的Bean通过此适配器进行适配、执行。

适配器配置如下:

<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />

org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter

要求编写的Handler实现 Controller接口。

      3.2.1.2 HttpRequestHandlerAdapter

HttpRequestHandlerAdapter,http请求处理器适配器,所有实现了org.springframework.web.HttpRequestHandler 接口的Bean通过此适配器进行适配、执行。

适配器配置如下:

<bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"/>

org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter

要求编写的Handler实现 HttpRequestHandler接口。

测试:

http://localhost:8080/springmvcfirst1217/queryItems3.action

可以成功访问

SpringMVC由浅入深day01_3非注解的处理器映射器和适配器的更多相关文章

  1. 【SpringMVC框架】非注解的处理器映射器和适配器

    参考来源:     http://blog.csdn.net/acmman/article/details/46968939 处理器映射器就是根据URL来找Handler,处理器适配器就是按照它要求的 ...

  2. springmvc两种非注解的处理器映射器

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  3. SpringMVC学习记录二——非注解和注解的处理器映射器和适配器

    3      非注解的处理器映射器和适配器 3.1      非注解的处理器映射器 处理器映射器: org.springframework.web.servlet.handler.BeanNameUr ...

  4. SpringMVC由浅入深day01_5注解的处理器映射器和适配器

    5 注解的处理器映射器和适配器 在spring3.1之前使用org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandle ...

  5. 02_springmvc处理器映射器和适配器(补充)

    一.非注解的处理器映射器 HandlerMapping 负责根据request请求找到对应的Handler处理器及Interceptor拦截器,将它们封装在HandlerExecutionChain ...

  6. springmvc03 非注解和注解处理器映射器和适配器

    1其它非注解处理器映射器和适配器 .1BeanNameUrlHandlerMapping(映射器) 根据请求url(XXXX.action)匹配spring容器bean的 name 找到对应的bean ...

  7. 【SpringMVC笔记】第四课 注解的处理器映射器和处理器适配器使用

    一.注意点: 版本问题 spring3.2以前的版本,注解的映射器和适配器使用以下两个类. org.springframework.web.servlet.mvc.annotation.Default ...

  8. springMVC非注解常用的"处理器映射器"、"适配器"、"处理器"

    非注解处理器映射器1. org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping url 到bean name的映射2. or ...

  9. springmvc两种非注解的处理器适配器

    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http:// ...

随机推荐

  1. centos7配置kerberos服务,并使用JAAS登录

    准备两个虚拟机:192.168.1.101.192.168.1.102,101作为kerberos的server端,102作为kerberos的client端.开启88端口. 1.安装kerberos ...

  2. matlab中log函数与rssi转距离

    我们通常所说的log是指以10为底的对数,而MATLAB中的log却不是这样.Matlab中的log函数在默认情况下是以e为底,即loge,如果需要计算以10为底的对数,那么需要用log10()函数. ...

  3. 我最喜欢的jQuery插件模板

    我使用jQuery已经有相当长的时间了,并且我会常常为它写一些插件(plugin).我尝试过用不同的方式去写,现在这个模板是我最喜欢的: 1 2 3 4 5 6 7 8 9 10 11 12 13 1 ...

  4. RIP路由协议及工作原理

    RIP路由协议及工作原理 RIP(Routing information Protocol,路由信息协议)是应用较早.使用较普遍的内部网关协议(Interior Gateway Protocol,IG ...

  5. 计蒜客2018 蓝桥杯省赛 B 组模拟赛(一)

    1,结果填空:年龄 今天蒜头君带着花椰妹和朋友们一起聚会,当朋友们问起年龄的时候,蒜头君打了一个哑谜(毕竟年龄是女孩子的隐私)说:“我的年龄是花椰妹年龄个位数和十位数之和的二倍”. 花椰妹看大家一脸懵 ...

  6. Lucene系列一:搜索引擎核心理论

    一.为什么需要搜索引擎 问题1:数据库索引的原理是怎样的? 索引原理:对列值创建排序存储,数据结构={列值.行地址}.在有序数据列表中就可以利用二分查找快速找到要查找的行的地址,再根据地址直接取行数据 ...

  7. e840. 监听JTabbedPane中选中卡片的改变

    A tabbed pane fires a change event whenever the selected tab is changed either by the user or progra ...

  8. unity------各种坐标理解

    本人学生一枚,刚接触Unity3D,若有理解得不对的地方,还望各路大神不吝赐教~ unity中的坐标系统包括世界坐标(World Space),屏幕坐标(Screen Space),视口坐标(View ...

  9. Linux 内存buffer与cache区别_003

    一.首先大概了解一下计算机CPU.Cache.Buffer.内存.硬盘.SWAP CPU也称为中央处理器(CPU,Central Processing Unit)是一块超大规模的集成电路,是一台计算机 ...

  10. Kafka 之 入门

    摘要: 最近研究采集层,对Kafka做了一个研究.分为入门,中级,高级步步进阶.本篇主要介绍基本概念,适用场景. 一.入门 1.    简介 Kafka is a distributed, parti ...