基于xml配置springmvc
controller关键代码
public class MenuController extends MultiActionController
方法:
public ModelAndView list(HttpServletRequest request, HttpServletResponse response) { CoreMenuQuery query = new CoreMenuQuery(); List<CoreMenu> list = coreMenuService.find(query); return new ModelAndView("index"); }
一定要
HttpServletRequest request, HttpServletResponse response
xml配置
<bean id="paraMethodResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver"> <property name="paramName" value="action"/> <property name="defaultMethodName" value="list"/> </bean> <!-- 页面View层基本信息设定 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/content/"/> <property name="suffix" value=".jsp"/> </bean> <!-- servlet映射列表,所有控制层Controller的servlet在这里定义 --> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/admin/index.htm">adminController</prop> <prop key="/menu/index.htm">adminController</prop> </props> </property> </bean> <bean id="adminController" class="com.core.action.AdminController"> </bean>
访问方式类似
http://localhost:8080/BaseS2I/menu/index.htm?action=list
action来自
<property name="paramName" value="action"/>