6 java configuration spring web-applications
在Struts 1中,您可以在struts-config.xml中获得如下声明:
<action path="/first" forward="/second.do">
Run Code Online (Sandbox Code Playgroud)
在Spring中是否也可以使用类似的东西,或者我只能将URL映射到控制器?我使用的是Spring 2.5.x.
我当然可以将URL映射到同一个控制器:
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/first.do">theController</prop>
<prop key="/second.do">theController</prop>
...
Run Code Online (Sandbox Code Playgroud)
或者也许使用以下内容org.springframework.web.servlet.mvc.ParameterizableViewController
:
<bean id="theDummyController" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
<property name="viewName" value="forward:second.do"/>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/first.do">theDummyController</prop>
<prop key="/second.do">theController</prop>
...
Run Code Online (Sandbox Code Playgroud)
我知道我可能会使事情复杂化,我应该坚持完成工作的简单事情,但我希望这更像是一种类型的陈述:"这个URL实际上是一个快捷方式(或别名)这个其他的网址"(不要问为什么......长篇故事...),ParameterizableViewController
但不完全可见.
那么,这可能吗?
谢谢!
小智 1
我最终创建了一个单独的 URL 处理程序映射,将 URL 别名分组在一起。然后,我对所包含的映射进行了非常详细的描述,例如:
<bean id="aliasUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<description>
<![CDATA[
The following URLs are in fact shortcuts (or aliases)
to other URLs etc etc (...I'll spare you the ugly part)
]]>
</description>
<property name="mappings">
<props>
<prop key="/first.do">theController</prop>
...
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/second.do">theController</prop>
...
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2189 次 |
最近记录: |