SpringMVC DispatcherServlet的handlerAdapters

 

一、interface HandlerAdapter
用于对不同框架实现的handler 返回一个通用的HandlerAdapter 对象。主要提供扩展性。
public interface HandlerAdapter {
   //判断给定的handler对象,这个HandlerAdapter 对象是否支持,一个HandlerAdapter 对应一个类型的handler
   boolean supports(Object handler); 
   //使用给定的handler处理request
   ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception;
  
   long getLastModified(HttpServletRequest request, Object handler);

}


在没有定义HandlerAdapter 的bean则默认使用:
org.springframework.web.servlet.HandlerAdapter=
org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,\
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,\
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
==============================================================

二、SimpleControllerHandlerAdapter

public class SimpleControllerHandlerAdapter implements HandlerAdapter {

	public boolean supports(Object handler) {
		return (handler instanceof Controller);
	}

	public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {

		return ((Controller) handler).handleRequest(request, response);
	}

	public long getLastModified(HttpServletRequest request, Object handler) {
		if (handler instanceof LastModified) {
			return ((LastModified) handler).getLastModified(request);
		}
		return -1L;
	}

}



public class LoginAction extends SimpleFormController 由这个SimpleControllerHandlerAdapter 处理。

=========================================================













你可能感兴趣的:(bean,mvc,Web,框架,servlet)