Top Description Fields Constructors Methods
org.springframework.web.servlet.mvc.method.annotation

public Class ViewNameMethodReturnValueHandler

extends Object
implements HandlerMethodReturnValueHandler
Class Inheritance
All Implemented Interfaces
org.springframework.web.method.support.HandlerMethodReturnValueHandler
Imports
org.springframework.core.MethodParameter, org.springframework.lang.Nullable, org.springframework.util.PatternMatchUtils, org.springframework.web.context.request.NativeWebRequest, org.springframework.web.method.support.HandlerMethodReturnValueHandler, .ModelAndViewContainer, org.springframework.web.servlet.RequestToViewNameTranslator

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 way depending on the presence of annotations like @ModelAttribute or @ResponseBody. Therefore, this handler should be configured after the handlers that support these annotations.

Authors
Rossen Stoyanchev, Juergen Hoeller
Since
3.1

Field Summary

Modifier and TypeField and Description
private String[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String[]
getRedirectPatterns()

The configured redirect patterns, if any.

public void
handleReturnValue(Object
the value returned from the handler method
returnValue
,
MethodParameter
the type of the return value. This type must have previously been passed to supportsReturnType which must have returned true.
returnType
,
ModelAndViewContainer
the ModelAndViewContainer for the current request
mavContainer
,
NativeWebRequest
the current request
webRequest
)

Implements org.springframework.web.method.support.HandlerMethodReturnValueHandler.handleReturnValue.

Handle the given return value by adding attributes to the model and setting a view or setting the ModelAndViewContainer#setRequestHandled flag to true to indicate the response has been handled directly.

protected boolean

Returns:

"true" if the given view name is recognized as a redirect view reference; "false" otherwise.
isRedirectViewName
(String
the view name to check, never null
viewName
)

Whether the given view name is a redirect view reference.

public void
setRedirectPatterns(String... redirectPatterns)

Configure one more simple patterns (as described in PatternMatchUtils#simpleMatch) to use in order to recognize custom redirect prefixes in addition to "redirect:".

public boolean
supportsReturnType(MethodParameter
the method return type to check
returnType
)

Implements org.springframework.web.method.support.HandlerMethodReturnValueHandler.supportsReturnType.

Whether the given method return type is supported by this handler.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

redirectPatternsback to summary
private String[] redirectPatterns
Annotations
@Nullable

Constructor Detail

ViewNameMethodReturnValueHandlerback to summary
public ViewNameMethodReturnValueHandler()

Method Detail

getRedirectPatternsback to summary
public String[] getRedirectPatterns()

The configured redirect patterns, if any.

Annotations
@Nullable
handleReturnValueback to summary
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception

Implements org.springframework.web.method.support.HandlerMethodReturnValueHandler.handleReturnValue.

Doc from org.springframework.web.method.support.HandlerMethodReturnValueHandler.handleReturnValue.

Handle the given return value by adding attributes to the model and setting a view or setting the ModelAndViewContainer#setRequestHandled flag to true to indicate the response has been handled directly.

Parameters
returnValue:Object

the value returned from the handler method

returnType:MethodParameter

the type of the return value. This type must have previously been passed to supportsReturnType which must have returned true.

mavContainer:ModelAndViewContainer

the ModelAndViewContainer for the current request

webRequest:NativeWebRequest

the current request

Annotations
@Override
Exceptions
Exception:
if the return value handling results in an error
isRedirectViewNameback to summary
protected boolean isRedirectViewName(String viewName)

Whether the given view name is a redirect view reference. The default implementation checks the configured redirect patterns and also if the view name starts with the "redirect:" prefix.

Parameters
viewName:String

the view name to check, never null

Returns:boolean

"true" if the given view name is recognized as a redirect view reference; "false" otherwise.

setRedirectPatternsback to summary
public void setRedirectPatterns(String... redirectPatterns)

Configure one more simple patterns (as described in PatternMatchUtils#simpleMatch) to use in order to recognize custom redirect prefixes in addition to "redirect:".

Note that simply configuring this property will not make a custom redirect prefix work. There must be a custom View that recognizes the prefix as well.

Since
4.1
supportsReturnTypeback to summary
public boolean supportsReturnType(MethodParameter returnType)

Implements org.springframework.web.method.support.HandlerMethodReturnValueHandler.supportsReturnType.

Doc from org.springframework.web.method.support.HandlerMethodReturnValueHandler.supportsReturnType.

Whether the given method return type is supported by this handler.

Parameters
returnType:MethodParameter

the method return type to check

Returns:boolean

true if this handler supports the supplied return type; false otherwise

Annotations
@Override