Spring mvc (二)

2014-11-24 11:57:17 · 作者: · 浏览: 99
给我提供的 源码方法建议,相信您可能有一定收获,如:
[java]
/**
* {@link org.springframework.web.servlet.mvc.Controller Controller}
* implementation that allows multiple request types to be handled by the same
* class. Subclasses of this class can handle several different types of
* request with methods of the form
*
*
public (ModelAndView | Map | String | void) actionName(HttpServletRequest request, HttpServletResponse response, [,HttpSession] [,AnyObject]);
*
* A Map return value indicates a model that is supposed to be passed to a default view
* (determined through a {@link org.springframework.web.servlet.RequestToViewNameTranslator}).
* A String return value indicates the name of a view to be rendered without a specific model.
*
*

May take a third parameter (of type {@link HttpSession}) in which an

* existing session will be required, or a third parameter of an arbitrary
* class that gets treated as the command (that is, an instance of the class
* gets created, and request parameters get bound to it)
*
*

These methods can throw any kind of exception, but should only let

* propagate those that they consider fatal, or which their class or superclass
* is prepared to catch by implementing an exception handler.
*
*

When returning just a {@link Map} instance view name translation will be

* used to generate the view name. The configured
* {@link org.springframework.web.servlet.RequestToViewNameTranslator} will be
* used to determine the view name.
*
*

When returning {@code void} a return value of {@code null} is

* assumed meaning that the handler method is responsible for writing the
* response directly to the supplied {@link HttpServletResponse}.
*
*

This model allows for rapid coding, but loses the advantage of

* compile-time checking. It is similar to a Struts {@code DispatchAction},
* but more sophisticated. Also supports delegation to another object.
*
*

An implementation of the {@link MethodNameResolver} interface defined in

* this package should return a method name for a given request, based on any
* aspect of the request, such as its URL or an "action" parameter. The actual
* strategy can be configured via the "methodNameResolver" bean property, for
* each {@code MultiActionController}.
*
*

The default {@code MethodNameResolver} is

* {@link InternalPathMethodNameResolver}; further included strategies are
* {@link PropertiesMethodNameResolver} and {@link ParameterMethodNameResolver}.
*
*

Subclasses can implement custom exception handler methods with names such

* as:
*
*
public ModelAndView anyMeaningfulName(HttpServletRequest request, HttpServletResponse response, ExceptionClass exception);
*
* The third parameter can be any subclass or {@link Exception} or
* {@link RuntimeException}.
*
*

There can also be an optional {@code xxxLastModified} method for

* handlers, of signature:
*
*
public long anyMeaningfulNameLastModified(HttpServletRequest request)
*
* If such a method is present, it will be invoked. Default return from
* {@code getLastModified} is -1, meaning that the content must always be
* regenerated.
*
*

Note that all handler methods need to be public and that

* method overloading is not allowed.
*