BeanNameUrlHandlerMapping SimpleUrlHandlerMapping之间的区别 [英] Difference between BeanNameUrlHandlerMapping SimpleUrlHandlerMapping
问题描述
Spring BeanNameUrlHandlerMapping和SimpleUrlHandlerMapping之间有什么区别?
What is the difference between Spring BeanNameUrlHandlerMapping and SimpleUrlHandlerMapping?
在浏览某个网站后,我了解
BeanNameUrlHandlerMapping是DispatcherServlet的默认HandlerMapping。
After going through some site I understand that BeanNameUrlHandlerMapping is the default HandlerMapping for DispatcherServlet.
同样在BeanNameUrlHandlerMapping中,您可以直接使用Controller映射url。
Also in BeanNameUrlHandlerMapping you can directly map url with Controller.
但同样可以使用SimpleUrlHandlerMapping完成。
but same thing can be done with SimpleUrlHandlerMapping as well.
我知道一些但不太清楚,它必须用
做点什么
I know something but not that much clear, that it has to do something with
name接受/但id不能.....但我很困惑。
name accepts / but id can't.....but i am confused.
究竟是什么差异?什么是SimpleUrlHandlerMapping的需要?
what is the exact diffrence? what is the need of SimpleUrlHandlerMapping?
请解释...谢谢。
推荐答案
如果我们想要将多个url映射到单个控制器类,我们必须注册多个url,这不是使用Spring IoC的好方法。
We have to register more than one urls if we want map more than one url to be mapped to a single controller class and this is not a good way to work with Spring IoC.
SimpleUrlHandlerMapping是一种使用map或property bean定义url映射的简单方法。这简化了Spring MVC中的url映射。
SimpleUrlHandlerMapping is a simple way to define url mapping using a map or property bean. This simplify the url mapping in Spring MVC.
示例BeanUrlHandlerMapping
<bean name="/hello.htm" class="com.raistudies.ui.comtroller.HelloController"/>
<bean name="/sayHello*" class="com.raistudies.ui.comtroller.HelloController"/>
<bean id="urlHandler" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
重要提示:
- 必须为每个url定义一个bean
- Spring容器有一个url的bean。虽然所有网址都由同一个bean提供
示例SimpleUrlHandlerMapping
<bean id="helloController" class="com.raistudies.ui.controller.HelloController"/>
<bean id="urlHandler" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/hello.htm" value-ref="helloController"/>
<entry key="/sayHello*" value-ref="helloController"/>
<entry key="/welcome.html" value-ref="helloController"/>
<entry key="/welcomeUser*" value-ref="helloController"/>
</map>
</property>
</bean>
重要提示:
- 对使用相同控制器的URL使用单个bean。
- 不必为每个URL定义bean
这篇关于BeanNameUrlHandlerMapping SimpleUrlHandlerMapping之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!