spring-framework / org.springframework.web.servlet.mvc.method.annotation

Package org.springframework.web.servlet.mvc.method.annotation

Types

AbstractJsonpResponseBodyAdvice

abstract class AbstractJsonpResponseBodyAdvice : AbstractMappingJacksonResponseBodyAdvice

A convenient base class for a ResponseBodyAdvice to instruct the org.springframework.http.converter.json.MappingJackson2HttpMessageConverter to serialize with JSONP formatting.

Sub-classes must specify the query parameter name(s) to check for the name of the JSONP callback function.

Sub-classes are likely to be annotated with the @ControllerAdvice annotation and auto-detected or otherwise must be registered directly with the RequestMappingHandlerAdapter and ExceptionHandlerExceptionResolver.

AsyncTaskMethodReturnValueHandler

open class AsyncTaskMethodReturnValueHandler : HandlerMethodReturnValueHandler

Handles return values of type WebAsyncTask.

CallableMethodReturnValueHandler

open class CallableMethodReturnValueHandler : HandlerMethodReturnValueHandler

Handles return values of type Callable.

DeferredResultMethodReturnValueHandler

open class DeferredResultMethodReturnValueHandler : HandlerMethodReturnValueHandler

Handler for return values of type DeferredResult, ListenableFuture, and CompletionStage.

ExtendedServletRequestDataBinder

open class ExtendedServletRequestDataBinder : ServletRequestDataBinder

Subclass of ServletRequestDataBinder that adds URI template variables to the values used for data binding.

HttpEntityMethodProcessor

open class HttpEntityMethodProcessor : AbstractMessageConverterMethodProcessor

Resolves HttpEntity and RequestEntity method argument values and also handles HttpEntity and ResponseEntity return values.

An HttpEntity return type has a specific purpose. Therefore this handler should be configured ahead of handlers that support any return value type annotated with @ModelAttribute or @ResponseBody to ensure they don't take over.

HttpHeadersReturnValueHandler

open class HttpHeadersReturnValueHandler : HandlerMethodReturnValueHandler

Handles HttpHeaders return values.

JsonViewRequestBodyAdvice

open class JsonViewRequestBodyAdvice : RequestBodyAdviceAdapter

A RequestBodyAdvice implementation that adds support for Jackson's @JsonView annotation declared on a Spring MVC @HttpEntity or @RequestBody method parameter.

The deserialization view specified in the annotation will be passed in to the org.springframework.http.converter.json.MappingJackson2HttpMessageConverter which will then use it to deserialize the request body with.

Note that despite @JsonView allowing for more than one class to be specified, the use for a request body advice is only supported with exactly one class argument. Consider the use of a composite interface.

JsonViewResponseBodyAdvice

open class JsonViewResponseBodyAdvice : AbstractMappingJacksonResponseBodyAdvice

A ResponseBodyAdvice implementation that adds support for Jackson's @JsonView annotation declared on a Spring MVC @RequestMapping or @ExceptionHandler method.

The serialization view specified in the annotation will be passed in to the org.springframework.http.converter.json.MappingJackson2HttpMessageConverter which will then use it to serialize the response body.

Note that despite @JsonView allowing for more than one class to be specified, the use for a response body advice is only supported with exactly one class argument. Consider the use of a composite interface.

MatrixVariableMapMethodArgumentResolver

open class MatrixVariableMapMethodArgumentResolver : HandlerMethodArgumentResolver

Resolves arguments of type Map annotated with where

MatrixVariableMethodArgumentResolver

open class MatrixVariableMethodArgumentResolver : AbstractNamedValueMethodArgumentResolver

Resolves arguments annotated with MatrixVariable.

If the method parameter is of type Map it will by resolved by MatrixVariableMapMethodArgumentResolver instead unless the annotation specifies a name in which case it is considered to be a single attribute of type map (vs multiple attributes collected in a map).

ModelAndViewMethodReturnValueHandler

open class ModelAndViewMethodReturnValueHandler : HandlerMethodReturnValueHandler

Handles return values of type ModelAndView copying view and model information to the ModelAndViewContainer.

If the return value is null, the ModelAndViewContainer#setRequestHandled(boolean) flag is set to true to indicate the request was handled directly.

A ModelAndView return type has a set purpose. Therefore this handler should be configured ahead of handlers that support any return value type annotated with @ModelAttribute or @ResponseBody to ensure they don't take over.

ModelAndViewResolverMethodReturnValueHandler

open class ModelAndViewResolverMethodReturnValueHandler : HandlerMethodReturnValueHandler

This return value handler is intended to be ordered after all others as it attempts to handle _any_ return value type (i.e. returns true for all return types).

The return value is handled either with a ModelAndViewResolver or otherwise by regarding it as a model attribute if it is a non-simple type. If neither of these succeeds (essentially simple type other than String), UnsupportedOperationException is raised.

Note: This class is primarily needed to support ModelAndViewResolver, which unfortunately cannot be properly adapted to the HandlerMethodReturnValueHandler contract since the HandlerMethodReturnValueHandler#supportsReturnType method cannot be implemented. Hence ModelAndViewResolvers are limited to always being invoked at the end after all other return value handlers have been given a chance. It is recommended to re-implement a ModelAndViewResolver as HandlerMethodReturnValueHandler, which also provides better access to the return type and method information.

PathVariableMapMethodArgumentResolver

open class PathVariableMapMethodArgumentResolver : HandlerMethodArgumentResolver

Resolves Map method arguments annotated with an @PathVariable where the annotation does not specify a path variable name. The created Map contains all URI template name/value pairs.

PathVariableMethodArgumentResolver

open class PathVariableMethodArgumentResolver : AbstractNamedValueMethodArgumentResolver, UriComponentsContributor

Resolves method arguments annotated with an @PathVariable.

An @PathVariable is a named value that gets resolved from a URI template variable. It is always required and does not have a default value to fall back on. See the base class org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver for more information on how named values are processed.

If the method parameter type is Map, the name specified in the annotation is used to resolve the URI variable String value. The value is then converted to a Map via type conversion, assuming a suitable Converter or PropertyEditor has been registered.

A WebDataBinder is invoked to apply type conversion to resolved path variable values that don't yet match the method parameter type.

RedirectAttributesMethodArgumentResolver

open class RedirectAttributesMethodArgumentResolver : HandlerMethodArgumentResolver

Resolves method arguments of type RedirectAttributes.

This resolver must be listed ahead of org.springframework.web.method.annotation.ModelMethodProcessor and org.springframework.web.method.annotation.MapMethodProcessor, which support Map and Model arguments both of which are "super" types of RedirectAttributes and would also attempt to resolve a RedirectAttributes argument.

RequestAttributeMethodArgumentResolver

open class RequestAttributeMethodArgumentResolver : AbstractNamedValueMethodArgumentResolver

Resolves method arguments annotated with an @RequestAttribute.

RequestBodyAdvice

interface RequestBodyAdvice

Allows customizing the request before its body is read and converted into an Object and also allows for processing of the resulting Object before it is passed into a controller method as an @RequestBody or an HttpEntity method argument.

Implementations of this contract may be registered directly with the RequestMappingHandlerAdapter or more likely annotated with @ControllerAdvice in which case they are auto-detected.

RequestPartMethodArgumentResolver

open class RequestPartMethodArgumentResolver : AbstractMessageConverterMethodArgumentResolver

Resolves the following method arguments:

  • Annotated with @RequestPart
  • Of type MultipartFile in conjunction with Spring's MultipartResolver abstraction
  • Of type javax.servlet.http.Part in conjunction with Servlet 3.0 multipart requests

When a parameter is annotated with @RequestPart, the content of the part is passed through an HttpMessageConverter to resolve the method argument with the 'Content-Type' of the request part in mind. This is analogous to what @RequestBody does to resolve an argument based on the content of a regular request.

When a parameter is not annotated or the name of the part is not specified, it is derived from the name of the method argument.

Automatic validation may be applied if the argument is annotated with @javax.validation.Valid. In case of validation failure, a MethodArgumentNotValidException is raised and a 400 response status code returned if org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver is configured.

RequestResponseBodyMethodProcessor

open class RequestResponseBodyMethodProcessor : AbstractMessageConverterMethodProcessor

Resolves method arguments annotated with @RequestBody and handles return values from methods annotated with @ResponseBody by reading and writing to the body of the request or response with an HttpMessageConverter.

An @RequestBody method argument is also validated if it is annotated with @javax.validation.Valid. In case of validation failure, MethodArgumentNotValidException is raised and results in an HTTP 400 response status code if DefaultHandlerExceptionResolver is configured.

ResponseBodyEmitter

open class ResponseBodyEmitter

A controller method return value type for asynchronous request processing where one or more objects are written to the response.

While org.springframework.web.context.request.async.DeferredResult is used to produce a single result, a ResponseBodyEmitter can be used to send multiple objects where each object is written with a compatible org.springframework.http.converter.HttpMessageConverter.

Supported as a return type on its own as well as within a org.springframework.http.ResponseEntity.

 @RequestMapping(value="/stream", method=RequestMethod.GET) public ResponseBodyEmitter handle() { ResponseBodyEmitter emitter = new ResponseBodyEmitter(); // Pass the emitter to another component... return emitter; } // in another thread emitter.send(foo1); // and again emitter.send(foo2); // and done emitter.complete(); 

ResponseBodyEmitterReturnValueHandler

open class ResponseBodyEmitterReturnValueHandler : HandlerMethodReturnValueHandler

Handler for return values of type ResponseBodyEmitter and sub-classes such as SseEmitter including the same types wrapped with ResponseEntity.

As of 5.0 also supports reactive return value types for any reactive library with registered adapters in ReactiveAdapterRegistry.

ResponseEntityExceptionHandler

abstract class ResponseEntityExceptionHandler

A convenient base class for ControllerAdvice classes that wish to provide centralized exception handling across all @RequestMapping methods through @ExceptionHandler methods.

This base class provides an @ExceptionHandler method for handling internal Spring MVC exceptions. This method returns a ResponseEntity for writing to the response with a HttpMessageConverter, in contrast to org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver which returns a org.springframework.web.servlet.ModelAndView.

If there is no need to write error content to the response body, or when using view resolution (e.g., via ContentNegotiatingViewResolver), then DefaultHandlerExceptionResolver is good enough.

Note that in order for an @ControllerAdvice sub-class to be detected, ExceptionHandlerExceptionResolver must be configured.

ServletCookieValueMethodArgumentResolver

open class ServletCookieValueMethodArgumentResolver : AbstractCookieValueMethodArgumentResolver

An org.springframework.web.method.annotation.AbstractCookieValueMethodArgumentResolver that resolves cookie values from an HttpServletRequest.

ServletInvocableHandlerMethod

open class ServletInvocableHandlerMethod : InvocableHandlerMethod

Extends InvocableHandlerMethod with the ability to handle return values through a registered HandlerMethodReturnValueHandler and also supports setting the response status based on a method-level @ResponseStatus annotation.

A null return value (including void) may be interpreted as the end of request processing in combination with a @ResponseStatus annotation, a not-modified check condition (see ServletWebRequest#checkNotModified(long)), or a method argument that provides access to the response stream.

ServletModelAttributeMethodProcessor

open class ServletModelAttributeMethodProcessor : ModelAttributeMethodProcessor

A Servlet-specific ModelAttributeMethodProcessor that applies data binding through a WebDataBinder of type ServletRequestDataBinder.

Also adds a fall-back strategy to instantiate the model attribute from a URI template variable or from a request parameter if the name matches the model attribute name and there is an appropriate type conversion strategy.

ServletRequestDataBinderFactory

open class ServletRequestDataBinderFactory : InitBinderDataBinderFactory

Creates a ServletRequestDataBinder.

ServletRequestMethodArgumentResolver

open class ServletRequestMethodArgumentResolver : HandlerMethodArgumentResolver

Resolves request-related method argument values of the following types:

  • WebRequest
  • ServletRequest
  • MultipartRequest
  • HttpSession
  • PushBuilder (as of Spring 5.0 on Servlet 4.0)
  • Principal
  • InputStream
  • Reader
  • HttpMethod (as of Spring 4.0)
  • Locale
  • TimeZone (as of Spring 4.0)
  • java.time.ZoneId (as of Spring 4.0 and Java 8)

ServletResponseMethodArgumentResolver

open class ServletResponseMethodArgumentResolver : HandlerMethodArgumentResolver

Resolves response-related method argument values of types:

  • ServletResponse
  • OutputStream
  • Writer

ServletWebArgumentResolverAdapter

open class ServletWebArgumentResolverAdapter : AbstractWebArgumentResolverAdapter

A Servlet-specific org.springframework.web.method.annotation.AbstractWebArgumentResolverAdapter that creates a NativeWebRequest from ServletRequestAttributes.

Note: This class is provided for backwards compatibility. However it is recommended to re-write a WebArgumentResolver as HandlerMethodArgumentResolver. For more details see javadoc of org.springframework.web.method.annotation.AbstractWebArgumentResolverAdapter.

SessionAttributeMethodArgumentResolver

open class SessionAttributeMethodArgumentResolver : AbstractNamedValueMethodArgumentResolver

Resolves method arguments annotated with an @SessionAttribute.

SseEmitter

open class SseEmitter : ResponseBodyEmitter

A specialization of ResponseBodyEmitter for sending Server-Sent Events.

StreamingResponseBody

interface StreamingResponseBody

A controller method return value type for asynchronous request processing where the application can write directly to the response OutputStream without holding up the Servlet container thread.

Note: when using this option it is highly recommended to configure explicitly the TaskExecutor used in Spring MVC for executing asynchronous requests. Both the MVC Java config and the MVC namespaces provide options to configure asynchronous handling. If not using those, an application can set the taskExecutor property of org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.

StreamingResponseBodyReturnValueHandler

open class StreamingResponseBodyReturnValueHandler : HandlerMethodReturnValueHandler

Supports return values of type org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody and also ResponseEntity<StreamingResponseBody>.

UriComponentsBuilderMethodArgumentResolver

open class UriComponentsBuilderMethodArgumentResolver : HandlerMethodArgumentResolver

Resolvers argument values of type UriComponentsBuilder.

The returned instance is initialized via ServletUriComponentsBuilder#fromServletMapping(HttpServletRequest).

ViewMethodReturnValueHandler

open class ViewMethodReturnValueHandler : HandlerMethodReturnValueHandler

Handles return values that are of type View.

A null return value is left as-is leaving it to the configured RequestToViewNameTranslator to select a view name by convention.

A View return type has a set purpose. Therefore this handler should be configured ahead of handlers that support any return value type annotated with @ModelAttribute or @ResponseBody to ensure they don't take over.

ViewNameMethodReturnValueHandler

open class ViewNameMethodReturnValueHandler : HandlerMethodReturnValueHandler

Handles return values of types void and String interpreting them as view name reference. As of 4.2, it also handles general CharSequence types, e.g. StringBuilder or Groovy's GString, as view names.

A null return value, either due to a void return type or as the actual return value is left as-is allowing the configured RequestToViewNameTranslator to select a view name by convention.

A String return value can be interpreted in more than one ways depending on the presence of annotations like @ModelAttribute or @ResponseBody. Therefore this handler should be configured after the handlers that support these annotations.