springMVC给我们提供Controller控制器,用来实现我们的逻辑处理,在Controller接口中定义的方法也是比较简单的,如下:

Controller接口及实现类:

springMVC源码--Controller控制器_ide

Controller有多个实现类,这些类就不做过多解释了,因为我们如果处理自己的业务还是需要重写他的handleRequest方法的。

Controller接口如下:

public interface Controller {

//执行请求处理操作,返回ModelAndView对象
ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception;

}


简单的定义一个处理操作:

public class ProductImplementController implements Controller {


@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView modelAndView = new ModelAndView("jsp/ProductForm");
return modelAndView;
}

}

springMVC的容器配置文件中注入这个Controller

<bean name="/input.action" class="com.tianjunwei.controller.ProductImplementController"></bean>

这样最终访问这个Controller时会跳到jsp/ProductForm的页面。