spring的ParameterMethodNameResolver的可以根据不同的参数执行不同方法,类似Struts的dyncaction
下面有一个例子
package ee.bug;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
public class ProductController extends MultiActionController {
/**
* Handles view
*/
public ModelAndView view(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.getOutputStream().print("Viewing");
return null;
}
/**
* Handles index
*/
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws Exception {
response.getOutputStream().print("index");
return null;
}
}
配置文件
<bean id="productMethodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
<property name="paramName"><value>method</value></property>
<property name="defaultMethodName"><value>view</value></property>
</bean>
<bean id="productController" class="ee.bug.ProductController">
<property name="methodNameResolver"><ref local="productMethodNameResolver"/></property>
</bean>
<property name="paramName"><value>method</value></property>参数名为method 默认为action
输入view.do?method=view 显示Viewing
输入view.do?method=indedx 显示index
输入/view.do?method=fdsf 显示404错误