Hi everyone,
Just curious what's the real benefit of a multi-action controller.
According to the documentation, a multi-action controller is ideally used for mapping multiple entries to the same controller (i.e. grouping of similar functionalities). Borrowing the codes from the Spring documentation (below), we mappy multiple requests into "retrieveIndex" which is defined in the delegate class.
=======COPY AND PASTE FROM SPRING DOCUMENTATION========
<bean id="propsResolver" class="org....mvc.multiaction.PropertiesMethodName Resolver">
<property name="mappings">
<props>
<prop key="/index/welcome.html">retrieveIndex</prop>
<prop key="/**/notwelcome.html">retrieveIndex</prop>
<prop key="/*/user?.html">retrieveIndex</prop>
</props>
</property>
</bean>
<bean id="paramMultiController" class="org....mvc.multiaction.MultiActionControlle r">
<property name="methodNameResolver"><ref bean="propsResolver"/></property>
<property name="delegate"><ref bean="sampleDelegate"/>
</bean>
public class SampleDelegate {
public ModelAndView retrieveIndex(
HttpServletRequest req,
HttpServletResponse resp) {
rerurn new ModelAndView("index", "date", new Long(System.currentTimeMillis()));
}
}
=====COPY AND PASTE FROM SPRING DOCUMENTATION======
I just wonder why do we bother using the multi-action controller when we can do something like:
=========WITHOUT USING MULTI-ACTION CONTROLLER=====
<bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/index/welcome.html">myController</prop>
<prop key="/**/notwelcome.html">myController</prop>
<prop key="/*/user?.html">myController</prop>
</props>
</property>
</bean>
<bean id="myController" class="com.web.controller.MyController">
<property name="successView"><value>myView</value></property>
</bean>
=========WITHOUT USING MULTI-ACTION CONTROLLER=====
As you can see in my example, MyController simply extends from "Controller" and multiple requests are mapped into this one controller.
Maybe I've missed something, but I don't see any value of spending the extra effort to configure the application to use the multi-action controller.
Thanks for your time.


Reply With Quote