类 UrlBasedViewResolver
- java.lang.Object
- org.springframework.web.reactive.result.view.ViewResolverSupport
- org.springframework.web.reactive.result.view.UrlBasedViewResolver
- 所有已实现的接口:
Aware
,InitializingBean
,ApplicationContextAware
,Ordered
,ViewResolver
public class UrlBasedViewResolver extends ViewResolverSupport implements ViewResolver, ApplicationContextAware, InitializingBean
AViewResolver
that allows direct resolution of symbolic view names to URLs without explicit mapping definitions. This is useful if symbolic names match the names of view resources in a straightforward manner (i.e. the symbolic name is the unique part of the resource's filename), without the need for a dedicated mapping to be defined for each view.Supports
AbstractUrlBasedView
subclasses likeFreeMarkerView
. The view class for all views generated by this resolver can be specified via the "viewClass" property.View names can either be resource URLs themselves, or get augmented by a specified prefix and/or suffix. Exporting an attribute that holds the RequestContext to all views is explicitly supported.
Example: prefix="templates/", suffix=".ftl", viewname=test -> "templates/test.ftl"
As a special feature, redirect URLs can be specified via the "redirect:" prefix. E.g.: "redirect:myAction" will trigger a redirect to the given URL, rather than resolution as standard view name. This is typically used for redirecting to a controller URL after finishing a form workflow.
Note: This class does not support localized resolution, i.e. resolving a symbolic view name to different resources depending on the current locale.
- 从以下版本开始:
- 5.0
- 作者:
- Rossen Stoyanchev, Sebastien Deleuze, Juergen Hoeller, Sam Brannen
字段概要
字段 修饰符和类型 字段 说明 static String
REDIRECT_URL_PREFIX
Prefix for special view names that specify a redirect URL (usually to a controller after a form has been submitted and processed).从类继承的字段 org.springframework.web.reactive.result.view.ViewResolverSupport
DEFAULT_CONTENT_TYPE
从接口继承的字段 org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
构造器概要
构造器 构造器 说明 UrlBasedViewResolver()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.protected View
applyLifecycleMethods(String viewName, AbstractUrlBasedView view)
Apply the containingApplicationContext
's lifecycle methods to the givenView
instance, if such a context is available.protected boolean
canHandle(String viewName, Locale locale)
Indicates whether or not thisViewResolver
can handle the supplied view name.protected AbstractUrlBasedView
createView(String viewName)
Creates a new View instance of the specified view class and configures it.ApplicationContext
getApplicationContext()
Return the containingApplicationContext
, if any.protected String
getPrefix()
Return the prefix that gets prepended to view names when building a URL.protected String
getRequestContextAttribute()
Return the name of theRequestContext
attribute for all views, if any.protected String
getSuffix()
Return the suffix that gets appended to view names when building a URL.protected Class<?>
getViewClass()
Return the view class to be used to create views.protected String[]
getViewNames()
Return the view names (or name patterns) that can be handled by thisViewResolver
.protected Class<?>
requiredViewClass()
Return the required type of view for this resolver.reactor.core.publisher.Mono<View>
resolveViewName(String viewName, Locale locale)
Resolve the view name to a View instance.void
setApplicationContext(ApplicationContext applicationContext)
Accept the containingApplicationContext
, if any.void
setPrefix(String prefix)
Set the prefix that gets prepended to view names when building a URL.void
setRedirectViewProvider(Function<String,RedirectView> redirectViewProvider)
URL basedRedirectView
provider which can be used to provide, for example, redirect views with a custom default status code.void
setRequestContextAttribute(String requestContextAttribute)
Set the name of theRequestContext
attribute for all views.void
setSuffix(String suffix)
Set the suffix that gets appended to view names when building a URL.void
setViewClass(Class<?> viewClass)
Set the view class to instantiate throughcreateView(String)
.void
setViewNames(String... viewNames)
Set the view names (or name patterns) that can be handled by thisViewResolver
.从类继承的方法 org.springframework.web.reactive.result.view.ViewResolverSupport
getDefaultCharset, getOrder, getSupportedMediaTypes, setDefaultCharset, setOrder, setSupportedMediaTypes
字段详细资料
REDIRECT_URL_PREFIX
public static final String REDIRECT_URL_PREFIX
Prefix for special view names that specify a redirect URL (usually to a controller after a form has been submitted and processed). Such view names will not be resolved in the configured default way but rather be treated as special shortcut.- 另请参阅:
- 常量字段值
构造器详细资料
UrlBasedViewResolver
public UrlBasedViewResolver()
方法详细资料
setViewClass
public void setViewClass(@Nullable Class<?> viewClass)
Set the view class to instantiate throughcreateView(String)
.- 参数:
viewClass
- a class that is assignable to the required view class which by default is AbstractUrlBasedView
getViewClass
@Nullable protected Class<?> getViewClass()
Return the view class to be used to create views.
requiredViewClass
protected Class<?> requiredViewClass()
Return the required type of view for this resolver. This implementation returnsAbstractUrlBasedView
.- 另请参阅:
AbstractUrlBasedView
setPrefix
public void setPrefix(@Nullable String prefix)
Set the prefix that gets prepended to view names when building a URL.
getPrefix
protected String getPrefix()
Return the prefix that gets prepended to view names when building a URL.
setSuffix
public void setSuffix(@Nullable String suffix)
Set the suffix that gets appended to view names when building a URL.
getSuffix
protected String getSuffix()
Return the suffix that gets appended to view names when building a URL.
setViewNames
public void setViewNames(@Nullable String... viewNames)
Set the view names (or name patterns) that can be handled by thisViewResolver
. View names can contain simple wildcards such that 'my*', '*Report' and '*Repo*' will all match the view name 'myReport'.
getViewNames
@Nullable protected String[] getViewNames()
Return the view names (or name patterns) that can be handled by thisViewResolver
.
setRedirectViewProvider
public void setRedirectViewProvider(Function<String,RedirectView> redirectViewProvider)
URL basedRedirectView
provider which can be used to provide, for example, redirect views with a custom default status code.
setRequestContextAttribute
public void setRequestContextAttribute(@Nullable String requestContextAttribute)
Set the name of theRequestContext
attribute for all views.- 参数:
requestContextAttribute
- name of the RequestContext attribute- 另请参阅:
AbstractView.setRequestContextAttribute(java.lang.String)
getRequestContextAttribute
@Nullable protected String getRequestContextAttribute()
Return the name of theRequestContext
attribute for all views, if any.
setApplicationContext
public void setApplicationContext(@Nullable ApplicationContext applicationContext)
Accept the containingApplicationContext
, if any.To be used for the initialization of newly created
View
instances, applying lifecycle callbacks and providing access to the containing environment.- 指定者:
setApplicationContext
在接口中ApplicationContextAware
- 参数:
applicationContext
- the ApplicationContext object to be used by this object- 另请参阅:
setViewClass(java.lang.Class<?>)
,createView(java.lang.String)
,applyLifecycleMethods(java.lang.String, org.springframework.web.reactive.result.view.AbstractUrlBasedView)
getApplicationContext
@Nullable public ApplicationContext getApplicationContext()
Return the containingApplicationContext
, if any.
afterPropertiesSet
public void afterPropertiesSet() throws Exception
从接口复制的说明:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.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
- 抛出:
Exception
- in the event of misconfiguration (such as failure to set an essential property) or if initialization fails for any other reason
resolveViewName
public reactor.core.publisher.Mono<View> resolveViewName(String viewName, Locale locale)
从接口复制的说明:ViewResolver
Resolve the view name to a View instance.- 指定者:
resolveViewName
在接口中ViewResolver
- 参数:
viewName
- the name of the view to resolvelocale
- the locale for the request- 返回:
- the resolved view or an empty stream
canHandle
protected boolean canHandle(String viewName, Locale locale)
Indicates whether or not thisViewResolver
can handle the supplied view name. If not, an empty result is returned. The default implementation checks against the configuredview names
.- 参数:
viewName
- the name of the view to retrievelocale
- the Locale to retrieve the view for- 返回:
- whether this resolver applies to the specified view
- 另请参阅:
PatternMatchUtils.simpleMatch(String, String)
createView
protected AbstractUrlBasedView createView(String viewName)
Creates a new View instance of the specified view class and configures it.Does not perform any lookup for pre-defined View instances.
Spring lifecycle methods as defined by the bean container do not have to be called here: They will be automatically applied afterwards, provided that an
ApplicationContext
is available.- 参数:
viewName
- the name of the view to build- 返回:
- the View instance
- 另请参阅:
getViewClass()
,applyLifecycleMethods(java.lang.String, org.springframework.web.reactive.result.view.AbstractUrlBasedView)
applyLifecycleMethods
protected View applyLifecycleMethods(String viewName, AbstractUrlBasedView view)
Apply the containingApplicationContext
's lifecycle methods to the givenView
instance, if such a context is available.- 参数:
viewName
- the name of the viewview
- the freshly created View instance, pre-configured withAbstractUrlBasedView
's properties- 返回:
- the
View
instance to use (either the original one or a decorated variant) - 另请参阅:
getApplicationContext()
,ApplicationContext.getAutowireCapableBeanFactory()
,AutowireCapableBeanFactory.initializeBean(java.lang.Object, java.lang.String)