类 RedirectView
- java.lang.Object
- org.springframework.web.reactive.result.view.AbstractView
- org.springframework.web.reactive.result.view.AbstractUrlBasedView
- org.springframework.web.reactive.result.view.RedirectView
- 所有已实现的接口:
Aware,BeanNameAware,InitializingBean,ApplicationContextAware,View
public class RedirectView extends AbstractUrlBasedView
View that redirects to an absolute or context relative URL. The URL may be a URI template in which case the URI template variables will be replaced with values from the model or with URI variables from the current request.By default
HttpStatus.SEE_OTHERis used but alternate status codes may be via constructor or setters arguments.- 从以下版本开始:
- 5.0
- 作者:
- Sebastien Deleuze, Rossen Stoyanchev
字段概要
从类继承的字段 org.springframework.web.reactive.result.view.AbstractView
logger, REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
从接口继承的字段 org.springframework.web.reactive.result.view.View
BINDING_CONTEXT_ATTRIBUTE
构造器概要
构造器 构造器 说明 RedirectView()Constructor for use as a bean.RedirectView(String redirectUrl)Create a newRedirectViewwith the given redirect URL.RedirectView(String redirectUrl, HttpStatus statusCode)Create a newRedirectViewwith the given URL and an alternate redirect status code such asHttpStatus.TEMPORARY_REDIRECTorHttpStatus.PERMANENT_REDIRECT.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidafterPropertiesSet()Invoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.protected StringBuilderappendCurrentRequestQuery(String targetUrl, ServerHttpRequest request)Append the query of the current request to the target redirect URL.booleancheckResourceExists(Locale locale)Check whether the resource for the configured URL actually exists.protected StringcreateTargetUrl(Map<String,Object> model, ServerWebExchange exchange)Create the target URL and, if necessary, pre-pend the contextPath, expand URI template variables, append the current request query, and apply the configuredRequestDataValueProcessor.protected StringBuilderexpandTargetUrlTemplate(String targetUrl, Map<String,Object> model, Map<String,String> uriVariables)Expand URI template variables in the target URL with either model attribute values or as a fallback with URI variable values from the current request.String[]getHosts()Return the configured application hosts.HttpStatusgetStatusCode()Get the redirect status code to use.booleanisContextRelative()Whether to interpret URLs as relative to the current context path.booleanisPropagateQuery()Whether the query string of the current URL is appended to the redirect URL.booleanisRedirectView()Whether this View does rendering by performing a redirect.protected booleanisRemoteHost(String targetUrl)Whether the given targetUrl has a host that is a "foreign" system in which caseHttpServletResponse.encodeRedirectURL(java.lang.String)will not be applied.protected reactor.core.publisher.Mono<Void>renderInternal(Map<String,Object> model, MediaType contentType, ServerWebExchange exchange)Convert model to request parameters and redirect to the given URL.protected reactor.core.publisher.Mono<Void>sendRedirect(String targetUrl, ServerWebExchange exchange)Send a redirect back to the HTTP client.voidsetContextRelative(boolean contextRelative)Whether to interpret a given redirect URLs that starts with a slash ("/") as relative to the current context path (true, the default) or to the web server root (false).voidsetHosts(String... hosts)Configure one or more hosts associated with the application.voidsetPropagateQuery(boolean propagateQuery)Whether to append the query string of the current URL to the redirect URL (true) or not (false, the default).voidsetStatusCode(HttpStatus statusCode)Set an alternate redirect status code such asHttpStatus.TEMPORARY_REDIRECTorHttpStatus.PERMANENT_REDIRECT.从类继承的方法 org.springframework.web.reactive.result.view.AbstractUrlBasedView
getUrl, setUrl, toString
从类继承的方法 org.springframework.web.reactive.result.view.AbstractView
createRequestContext, formatViewName, getApplicationContext, getBeanName, getDefaultCharset, getModelAttributes, getRequestContextAttribute, getRequestDataValueProcessor, getSupportedMediaTypes, obtainApplicationContext, render, resolveAsyncAttributes, resolveAsyncAttributes, setApplicationContext, setBeanName, setDefaultCharset, setRequestContextAttribute, setSupportedMediaTypes
构造器详细资料
RedirectView
public RedirectView()
Constructor for use as a bean.
RedirectView
public RedirectView(String redirectUrl)
Create a newRedirectViewwith the given redirect URL. Status codeHttpStatus.SEE_OTHERis used by default.
RedirectView
public RedirectView(String redirectUrl, HttpStatus statusCode)
Create a newRedirectViewwith the given URL and an alternate redirect status code such asHttpStatus.TEMPORARY_REDIRECTorHttpStatus.PERMANENT_REDIRECT.
方法详细资料
setStatusCode
public void setStatusCode(HttpStatus statusCode)
Set an alternate redirect status code such asHttpStatus.TEMPORARY_REDIRECTorHttpStatus.PERMANENT_REDIRECT.
getStatusCode
public HttpStatus getStatusCode()
Get the redirect status code to use.
setContextRelative
public void setContextRelative(boolean contextRelative)
Whether to interpret a given redirect URLs that starts with a slash ("/") as relative to the current context path (true, the default) or to the web server root (false).
isContextRelative
public boolean isContextRelative()
Whether to interpret URLs as relative to the current context path.
setPropagateQuery
public void setPropagateQuery(boolean propagateQuery)
Whether to append the query string of the current URL to the redirect URL (true) or not (false, the default).
isPropagateQuery
public boolean isPropagateQuery()
Whether the query string of the current URL is appended to the redirect URL.
setHosts
public void setHosts(@Nullable String... hosts)
Configure one or more hosts associated with the application. All other hosts will be considered external hosts.In effect this provides a way turn off encoding for URLs that have a host and that host is not listed as a known host.
If not set (the default) all redirect URLs are encoded.
- 参数:
hosts- one or more application hosts
afterPropertiesSet
public void afterPropertiesSet() throws Exception
从接口复制的说明:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- 指定者:
afterPropertiesSet在接口中InitializingBean- 覆盖:
afterPropertiesSet在类中AbstractUrlBasedView- 抛出:
Exception- in the event of misconfiguration (such as failure to set an essential property) or if initialization fails for any other reason
isRedirectView
public boolean isRedirectView()
从接口复制的说明:ViewWhether this View does rendering by performing a redirect.
checkResourceExists
public boolean checkResourceExists(Locale locale) throws Exception
从类复制的说明:AbstractUrlBasedViewCheck whether the resource for the configured URL actually exists.- 指定者:
checkResourceExists在类中AbstractUrlBasedView- 参数:
locale- the desired Locale that we're looking for- 返回:
falseif the resource existsfalseif we know that it does not exist- 抛出:
Exception- if the resource exists but is invalid (e.g. could not be parsed)
renderInternal
protected reactor.core.publisher.Mono<Void> renderInternal(Map<String,Object> model, @Nullable MediaType contentType, ServerWebExchange exchange)
Convert model to request parameters and redirect to the given URL.- 指定者:
renderInternal在类中AbstractView- 参数:
model- combined output Map (nevernull), with dynamic values taking precedence over static attributescontentType- the content type selected to render with, which should match one of the supported media typesexchange- current exchange- 返回:
- a
Monothat represents when and if rendering succeeds
createTargetUrl
protected final String createTargetUrl(Map<String,Object> model, ServerWebExchange exchange)
Create the target URL and, if necessary, pre-pend the contextPath, expand URI template variables, append the current request query, and apply the configuredRequestDataValueProcessor.
expandTargetUrlTemplate
protected StringBuilder expandTargetUrlTemplate(String targetUrl, Map<String,Object> model, Map<String,String> uriVariables)
Expand URI template variables in the target URL with either model attribute values or as a fallback with URI variable values from the current request. Values are encoded.
appendCurrentRequestQuery
protected StringBuilder appendCurrentRequestQuery(String targetUrl, ServerHttpRequest request)
Append the query of the current request to the target redirect URL.
sendRedirect
protected reactor.core.publisher.Mono<Void> sendRedirect(String targetUrl, ServerWebExchange exchange)
Send a redirect back to the HTTP client.- 参数:
targetUrl- the target URL to redirect toexchange- current exchange
isRemoteHost
protected boolean isRemoteHost(String targetUrl)
Whether the given targetUrl has a host that is a "foreign" system in which caseHttpServletResponse.encodeRedirectURL(java.lang.String)will not be applied. This method returnstrueif thesetHosts(String[])property is configured and the target URL has a host that does not match.- 参数:
targetUrl- the target redirect URL- 返回:
truethe target URL has a remote host,falseif it the URL does not have a host or the "host" property is not configured.