类 AbstractView
- java.lang.Object
- org.springframework.web.reactive.result.view.AbstractView
- 所有已实现的接口:
Aware
,BeanNameAware
,ApplicationContextAware
,View
- 直接已知子类:
AbstractUrlBasedView
public abstract class AbstractView extends Object implements View, BeanNameAware, ApplicationContextAware
Base class forView
implementations.- 从以下版本开始:
- 5.0
- 作者:
- Rossen Stoyanchev, Sam Brannen
字段概要
字段 修饰符和类型 字段 说明 protected Log
logger
Logger that is available to subclasses.static String
REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
Well-known name for the RequestDataValueProcessor in the bean factory.从接口继承的字段 org.springframework.web.reactive.result.view.View
BINDING_CONTEXT_ATTRIBUTE
构造器概要
构造器 构造器 说明 AbstractView()
AbstractView(ReactiveAdapterRegistry reactiveAdapterRegistry)
方法概要
所有方法 实例方法 抽象方法 具体方法 已过时的方法 修饰符和类型 方法 说明 protected RequestContext
createRequestContext(ServerWebExchange exchange, Map<String,Object> model)
Create aRequestContext
to expose under the specified attribute name.protected String
formatViewName()
ApplicationContext
getApplicationContext()
String
getBeanName()
Get the view's name.Charset
getDefaultCharset()
Get the default charset, used when the content type does not contain one.protected reactor.core.publisher.Mono<Map<String,Object>>
getModelAttributes(Map<String,?> model, ServerWebExchange exchange)
Prepare the model to use for rendering.String
getRequestContextAttribute()
Get the name of theRequestContext
attribute for this view, if any.protected RequestDataValueProcessor
getRequestDataValueProcessor()
Get theRequestDataValueProcessor
to use.List<MediaType>
getSupportedMediaTypes()
Get the configured media types supported by this view.protected ApplicationContext
obtainApplicationContext()
Obtain theApplicationContext
for actual use.reactor.core.publisher.Mono<Void>
render(Map<String,?> model, MediaType contentType, ServerWebExchange exchange)
Prepare the model to render.protected abstract reactor.core.publisher.Mono<Void>
renderInternal(Map<String,Object> renderAttributes, MediaType contentType, ServerWebExchange exchange)
Subclasses must implement this method to actually render the view.protected reactor.core.publisher.Mono<Void>
resolveAsyncAttributes(Map<String,Object> model)
已过时。as of 5.1.8 this method is still invoked but it is a no-op.protected reactor.core.publisher.Mono<Void>
resolveAsyncAttributes(Map<String,Object> model, ServerWebExchange exchange)
Use the configuredReactiveAdapterRegistry
to adapt asynchronous attributes toMono<T>
orMono<List<T>>
and then wait to resolve them into actual values.void
setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext that this object runs in.void
setBeanName(String beanName)
Set the view's name.void
setDefaultCharset(Charset defaultCharset)
Set the default charset for this view, used when the content type does not contain one.void
setRequestContextAttribute(String requestContextAttribute)
Set the name of theRequestContext
attribute for this view.void
setSupportedMediaTypes(List<MediaType> supportedMediaTypes)
Set the supported media types for this view.String
toString()
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
从接口继承的方法 org.springframework.web.reactive.result.view.View
isRedirectView
字段详细资料
REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
public static final String REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
Well-known name for the RequestDataValueProcessor in the bean factory.- 另请参阅:
- 常量字段值
构造器详细资料
AbstractView
public AbstractView()
AbstractView
public AbstractView(ReactiveAdapterRegistry reactiveAdapterRegistry)
方法详细资料
setSupportedMediaTypes
public void setSupportedMediaTypes(List<MediaType> supportedMediaTypes)
Set the supported media types for this view.Default is
"text/html;charset=UTF-8"
.
getSupportedMediaTypes
public List<MediaType> getSupportedMediaTypes()
Get the configured media types supported by this view.- 指定者:
getSupportedMediaTypes
在接口中View
setDefaultCharset
public void setDefaultCharset(Charset defaultCharset)
Set the default charset for this view, used when the content type does not contain one.Default is UTF 8.
getDefaultCharset
public Charset getDefaultCharset()
Get the default charset, used when the content type does not contain one.
setRequestContextAttribute
public void setRequestContextAttribute(@Nullable String requestContextAttribute)
Set the name of theRequestContext
attribute for this view.Default is none (
null
).
getRequestContextAttribute
@Nullable public String getRequestContextAttribute()
Get the name of theRequestContext
attribute for this view, if any.
setBeanName
public void setBeanName(@Nullable String beanName)
Set the view's name. Helpful for traceability.Framework code must call this when constructing views.
- 指定者:
setBeanName
在接口中BeanNameAware
- 参数:
beanName
- the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use theBeanFactoryUtils.originalBeanName(String)
method to extract the original bean name (without suffix), if desired.
getBeanName
@Nullable public String getBeanName()
Get the view's name.Should never be
null
if the view was correctly configured.
setApplicationContext
public void setApplicationContext(@Nullable ApplicationContext applicationContext)
从接口复制的说明:ApplicationContextAware
Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.Invoked after population of normal bean properties but before an init callback such as
InitializingBean.afterPropertiesSet()
or a custom init-method. Invoked afterResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)
,ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
andMessageSourceAware
, if applicable.- 指定者:
setApplicationContext
在接口中ApplicationContextAware
- 参数:
applicationContext
- the ApplicationContext object to be used by this object- 另请参阅:
BeanInitializationException
getApplicationContext
@Nullable public ApplicationContext getApplicationContext()
obtainApplicationContext
protected final ApplicationContext obtainApplicationContext()
Obtain theApplicationContext
for actual use.- 返回:
- the
ApplicationContext
(nevernull
) - 抛出:
IllegalStateException
- if the ApplicationContext cannot be obtained- 另请参阅:
getApplicationContext()
render
public reactor.core.publisher.Mono<Void> render(@Nullable Map<String,?> model, @Nullable MediaType contentType, ServerWebExchange exchange)
Prepare the model to render.- 指定者:
render
在接口中View
- 参数:
model
- a map with attribute names as keys and corresponding model objects as values (the map can also benull
in case of an empty model)contentType
- the content type selected to render with, which should match one of thesupported media types
exchange
- the current exchange- 返回:
- a
Mono
that represents when and if rendering succeeds
getModelAttributes
protected reactor.core.publisher.Mono<Map<String,Object>> getModelAttributes(@Nullable Map<String,?> model, ServerWebExchange exchange)
Prepare the model to use for rendering.The default implementation creates a combined output Map that includes model as well as static attributes with the former taking precedence.
resolveAsyncAttributes
protected reactor.core.publisher.Mono<Void> resolveAsyncAttributes(Map<String,Object> model, ServerWebExchange exchange)
Use the configuredReactiveAdapterRegistry
to adapt asynchronous attributes toMono<T>
orMono<List<T>>
and then wait to resolve them into actual values. When the returnedMono<Void>
completes, the asynchronous attributes in the model will have been replaced with their corresponding resolved values.- 返回:
- result a
Mono
that completes when the model is ready - 从以下版本开始:
- 5.1.8
resolveAsyncAttributes
@Deprecated protected reactor.core.publisher.Mono<Void> resolveAsyncAttributes(Map<String,Object> model)
已过时。as of 5.1.8 this method is still invoked but it is a no-op. Please useresolveAsyncAttributes(Map, ServerWebExchange)
instead. It is invoked after this one and does the actual work.Use the configuredReactiveAdapterRegistry
to adapt asynchronous attributes toMono<T>
orMono<List<T>>
and then wait to resolve them into actual values. When the returnedMono<Void>
completes, the asynchronous attributes in the model would have been replaced with their corresponding resolved values.- 返回:
- result
Mono
that completes when the model is ready
createRequestContext
protected RequestContext createRequestContext(ServerWebExchange exchange, Map<String,Object> model)
Create aRequestContext
to expose under the specified attribute name.The default implementation creates a standard
RequestContext
instance for the given exchange and model.Can be overridden in subclasses to create custom instances.
- 参数:
exchange
- the current exchangemodel
- a combined output Map (nevernull
), with dynamic values taking precedence over static attributes- 返回:
- the
RequestContext
instance - 另请参阅:
setRequestContextAttribute(java.lang.String)
getRequestDataValueProcessor
@Nullable protected RequestDataValueProcessor getRequestDataValueProcessor()
Get theRequestDataValueProcessor
to use.The default implementation looks in the
ApplicationContext
for aRequestDataValueProcessor
bean with the nameREQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME
.- 返回:
- the
RequestDataValueProcessor
, ornull
if there is none in the application context
renderInternal
protected abstract reactor.core.publisher.Mono<Void> renderInternal(Map<String,Object> renderAttributes, @Nullable MediaType contentType, ServerWebExchange exchange)
Subclasses must implement this method to actually render the view.- 参数:
renderAttributes
- 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
Mono
that represents when and if rendering succeeds
formatViewName
protected String formatViewName()