In Spring MVC application, the SimpleUrlHandlerMapping is the most flexible handler mapping class, which allow developer to specify the mapping of URL pattern and handlers explicitly.

The SimpleUrlHandlerMapping can be declared in two ways.

1. Method 1 – prop key

The property keys are the URL patterns while the property values are the handler IDs or names.

<beans ...>

	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/welcome.htm">welcomeController</prop>
<prop key="/*/welcome.htm">welcomeController</prop>
<prop key="/helloGuest.htm">helloGuestController</prop>
</props>
</property>
</bean> <bean id="welcomeController"
class="com.mkyong.common.controller.WelcomeController" /> <bean id="helloGuestController"
class="com.mkyong.common.controller.HelloGuestController" /> </beans>

2. Method 1 – value

The left side are the URL patterns while the right side are the handler IDs or names, separate by a equal symbol “=”.

<beans ...>

	<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/welcome.htm=welcomeController
/*/welcome.htm=welcomeController
/helloGuest.htm=helloGuestController
</value>
</property>
</bean> <bean id="welcomeController"
class="com.mkyong.common.controller.WelcomeController" /> <bean id="helloGuestController"
class="com.mkyong.common.controller.HelloGuestController" /> </beans>

3. Demo

Both are defined the same handler mappings.

/welcome.htm –> welcomeController.

/{anything}/welcome.htm –> welcomeController.

/helloGuest.htm –> helloGuestController.

最新文章

  1. SQLServer转MYSQL的方法(连数据)
  2. 对应键盘的ASCII码(备忘)
  3. Toast报错 android.content.res.Resources$NotFoundException
  4. 第三次作业之Calculator项目随笔
  5. java常用重构优化总结--自己亲身体验
  6. 一句代码,更加优雅的调用KVO和通知
  7. Xamarin for OSX – SetUp
  8. 80x86汇编小站站长简单介绍-2014年08月23日
  9. HDU_1245_Saving James Bond_最短路
  10. Vue01 Vue介绍、Vue使用、Vue实例的创建、数据绑定、Vue实例的生命周期、差值与表达式、指令与事件、语法糖
  11. webstorm中github的配置
  12. Python 入门基础15 --shutil、shelve、log常用模块2、项目结构
  13. Hadoop 管理工具HUE配置-HBase配置
  14. CDQ分治与整体二分学习笔记
  15. 动态ip、静态ip、pppoe拨号的区别
  16. 在C#中对枚举进行位运算--枚举组合
  17. linux c语言开发工具
  18. (第三周)wc.exe—命令行实现对指定目录下文件的操作
  19. CSS的力量:用一个DIV画图
  20. 详解Vue中的nextTick

热门文章

  1. ios跳转
  2. apk反编译(3)smali语法
  3. Word 中没有Endnote工具栏的解决方法
  4. Ural1076(km算法)
  5. bzoj1975
  6. bzoj2324营救皮卡丘
  7. UVa 10129 (并查集 + 欧拉路径) Play on Words
  8. poj 2230 Watchcow(欧拉回路)
  9. Builder模式在Java中的应用(转)
  10. Oracle 隔离级别