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