1) org.springframework.web.servlet.mvc.ParameterizableViewController
如果請求是/hello.action的請求路徑,則直接跳轉到/jsp/success.jsp頁面,不經過程式員定義的控制器Action
<!-- /index.action請求,直接轉發到/index.jsp頁面 -->
<bean name="/index.action" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
<property name="viewName" value="/index.jsp"/>
</bean>
<!-- 注冊視圖解析器(view包)(架構)
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"/>
<property name="suffix" value=".jsp"/>
</bean>
-->
public class AdminAction extends AbstractCommandController{
public AdminAction(){
this.setCommandClass(Admin.class);
}
@Override
protected ModelAndView handle(HttpServletRequest request,HttpServletResponse response, Object obj, BindException bindException)throws Exception {
System.out.println("AdminAction::handle");
ModelAndView modelAndView = new ModelAndView();
Admin admin = null;
if(obj instanceof Admin){
admin = (Admin) obj;
}
modelAndView.addObject("username",admin.getUsername());
modelAndView.addObject("gender",admin.getGender());
modelAndView.addObject("hiredate",admin.getHiredate());
modelAndView.setViewName("/jsp/success.jsp");
return modelAndView;
}
}
<!-- 請求處理類 -->
<bean name="/add.action" class="loaderman.javaee.springmvc.controller.AdminAction">
</bean>
<!-- 映射器 -->
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
</bean>