在springMVC-servlet.xml中配置html
<bean id="paramMethodResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver"> <property name="paramName" value="action"></property> </bean> <!--處理請求--> <bean name="/multi" class="com.tgb.web.controller.MultiController"> <property name="methodNameResolver"> <ref bean="paramMethodResolver"/> </property> </bean>
Controller類:MultiController.java 兩個方法,add()和update(), 經過請求參數 ?action=add或者action=update來調用方法
java
public class MultiController extends MultiActionController { public ModelAndView add(HttpServletRequest req, HttpServletResponse res) { System.out.println("---add---"); return new ModelAndView("/multi", "method", "add"); } public ModelAndView update(HttpServletRequest req, HttpServletResponse res) { System.out.println("---update---"); return new ModelAndView("/multi", "method", "update"); } }
請求頁面:multi.jspweb
<body> <h1>一個controller寫多個方法</h1> 本次方法是:${method }<br /> </body>
請求鏈接 /multi?action=addspring
/multi?action=update
mvc