控制器Controller

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>
      -->

2)  org.springframework.web.servlet.mvc.AbstractCommandController

能够以实体的形式,收集客户端参数

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>

 

posted on 2018-12-04 11:40  LoaderMan  阅读(287)  评论(0编辑  收藏  举报

导航