类 UrlBasedViewResolver
- 所有已实现的接口:
cn.taketoday.beans.factory.Aware,cn.taketoday.context.ApplicationContextAware,cn.taketoday.core.Ordered,ViewResolver
- 直接已知子类:
AbstractTemplateViewResolver,InternalResourceViewResolver,ScriptTemplateViewResolver,XsltViewResolver
ViewResolver
interface, allowing for direct resolution of symbolic view names to URLs,
without explicit mapping definitions. This is useful if your symbolic names
match the names of your 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 like InternalResourceView
and FreeMarkerView.
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="/WEB-INF/jsp/", suffix=".jsp", viewname="test" → "/WEB-INF/jsp/test.jsp"
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.
Furthermore, forward URLs can be specified via the "forward:" prefix. E.g.: "forward:myAction" will trigger a forward to the given URL, rather than resolution as standard view name. This is typically used for controller URLs; it is not supposed to be used for JSP URLs - use logical view names there.
Note: This class does not support localized resolution, i.e. resolving a symbolic view name to different resources depending on the current locale.
Note: When chaining ViewResolvers, a UrlBasedViewResolver will check whether
the specified resource actually exists.
However, with InternalResourceView, it is not generally possible to
determine the existence of the target resource upfront. In such a scenario,
a UrlBasedViewResolver will always return a View for any given view name;
as a consequence, it should be configured as the last ViewResolver in the chain.
- 从以下版本开始:
- 4.0
- 作者:
- Juergen Hoeller, Rob Harrop, Sam Brannen
- 另请参阅:
-
嵌套类概要
从类继承的嵌套类/接口 cn.taketoday.web.view.AbstractCachingViewResolver
AbstractCachingViewResolver.CacheFilter -
字段概要
字段修饰符和类型字段说明private Stringprivate Booleanprivate String[]private booleanprivate Booleanstatic final StringPrefix for special view names that specify a forward URL (usually to a controller after a form has been submitted and processed).private intprivate Stringstatic final StringPrefix for special view names that specify a redirect URL (usually to a controller after a form has been submitted and processed).private booleanprivate booleanprivate StringMap of static attributes, keyed by attribute name (String).private Stringprivate Class<?>private String[]从类继承的字段 cn.taketoday.web.view.AbstractCachingViewResolver
DEFAULT_CACHE_FILTER, DEFAULT_CACHE_LIMIT, UNRESOLVED_VIEW从类继承的字段 cn.taketoday.context.support.ApplicationObjectSupport
applicationContext, log, messageSourceAccessor从接口继承的字段 cn.taketoday.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected ViewapplyLifecycleMethods(String viewName, AbstractUrlBasedView view) Apply the containingApplicationContext's lifecycle methods to the givenViewinstance, if such a context is available.protected AbstractUrlBasedViewCreates a new View instance of the specified view class and configures it.protected booleanIndicates whether or not thisViewResolvercan handle the supplied view name.protected ViewcreateView(String viewName, Locale locale) Overridden to implement check for "redirect:" prefix.Allow Map access to the static attributes for views returned by this resolver, with the option to add or override specific entries.protected ObjectgetCacheKey(String viewName, Locale locale) This implementation returns just the view name, as this ViewResolver doesn't support localized resolution.protected StringReturn the content type for all views, if any.protected Booleanprotected String[]protected BooleanReturn whether views resolved by this resolver should add path variables to the model or not.intgetOrder()protected StringReturn the prefix that gets prepended to view names when building a URL.protected StringReturn the name of the RequestContext attribute for all views, if any.protected StringReturn the suffix that gets appended to view names when building a URL.protected Class<?>Return the view class to be used to create views.protected String[]Return the view names (or name patterns) that can be handled by thisViewResolver.protected voidprotected AbstractUrlBasedViewInstantiate the specified view class.protected booleanReturn whether to interpret a given redirect URL that starts with a slash ("/") as relative to the current ServletContext, i.e. as relative to the web application root.protected booleanReturn whether redirects should stay compatible with HTTP 1.0 clients.protected ViewDelegates tobuildViewfor creating a new instance of the specified view class.protected Class<?>Return the required type of view for this resolver.voidsetAttributes(Properties props) Set static attributes from ajava.util.Propertiesobject, for all views returned by this resolver.voidsetAttributesMap(Map<String, ?> attributes) Set static attributes from a Map, for all views returned by this resolver.voidsetContentType(String contentType) Set the content type for all views.voidsetExposeContextBeansAsAttributes(boolean exposeContextBeansAsAttributes) Set whether to make all Framework beans in the application context accessible as request attributes, through lazy checking once an attribute gets accessed.voidsetExposedContextBeanNames(String... exposedContextBeanNames) Specify the names of beans in the context which are supposed to be exposed.voidsetExposeOutputRedirectModel(boolean exposeOutputRedirectModel) setexposeOutputRedirectModelto determine if all 'output' RedirectModel should be put into modelvoidsetExposePathVariables(Boolean exposePathVariables) Specify whether views resolved by this resolver should add path variables to the model or not.voidsetOrder(int order) Specify the order value for this ViewResolver bean.voidSet the prefix that gets prepended to view names when building a URL.voidsetRedirectContextRelative(boolean redirectContextRelative) Set whether to interpret a given redirect URL that starts with a slash ("/") as relative to the current ServletContext, i.e. as relative to the web application root.voidsetRedirectHttp10Compatible(boolean redirectHttp10Compatible) Set whether redirects should stay compatible with HTTP 1.0 clients.voidsetRequestContextAttribute(String requestContextAttribute) Set the name of the RequestContext attribute for all views.voidSet the suffix that gets appended to view names when building a URL.voidsetViewClass(Class<?> viewClass) Set the view class that should be used to create views.voidsetViewNames(String... viewNames) Set the view names (or name patterns) that can be handled by thisViewResolver.从类继承的方法 cn.taketoday.web.view.AbstractCachingViewResolver
clearCache, getCacheFilter, getCacheLimit, isCache, isCacheUnresolved, removeFromCache, resolveViewName, setCache, setCacheFilter, setCacheLimit, setCacheUnresolved从类继承的方法 cn.taketoday.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, isContextRequired, obtainApplicationContext, requiredContextClass, setApplicationContext, unwrapContext, unwrapFactory
-
字段详细资料
-
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.- 另请参阅:
-
FORWARD_URL_PREFIX
Prefix for special view names that specify a forward 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.- 另请参阅:
-
viewClass
-
prefix
-
suffix
-
contentType
-
redirectContextRelative
private boolean redirectContextRelative -
redirectHttp10Compatible
private boolean redirectHttp10Compatible -
requestContextAttribute
-
staticAttributes
Map of static attributes, keyed by attribute name (String). -
exposePathVariables
-
exposeContextBeansAsAttributes
-
exposedContextBeanNames
-
viewNames
-
order
private int order -
exposeOutputRedirectModel
private boolean exposeOutputRedirectModel
-
-
构造器详细资料
-
UrlBasedViewResolver
public UrlBasedViewResolver()
-
-
方法详细资料
-
setViewClass
Set the view class that should be used to create views.- 参数:
viewClass- a class that is assignable to the required view class (by default: AbstractUrlBasedView)- 另请参阅:
-
getViewClass
Return the view class to be used to create views. -
setPrefix
Set the prefix that gets prepended to view names when building a URL. -
getPrefix
Return the prefix that gets prepended to view names when building a URL. -
setSuffix
Set the suffix that gets appended to view names when building a URL. -
getSuffix
Return the suffix that gets appended to view names when building a URL. -
setContentType
Set the content type for all views.May be ignored by view classes if the view itself is assumed to set the content type, e.g. in case of JSPs.
-
getContentType
Return the content type for all views, if any. -
setRedirectContextRelative
public void setRedirectContextRelative(boolean redirectContextRelative) Set whether to interpret a given redirect URL that starts with a slash ("/") as relative to the current ServletContext, i.e. as relative to the web application root.Default is "true": A redirect URL that starts with a slash will be interpreted as relative to the web application root, i.e. the context path will be prepended to the URL.
Redirect URLs can be specified via the "redirect:" prefix. E.g.: "redirect:myAction"
-
isRedirectContextRelative
protected boolean isRedirectContextRelative()Return whether to interpret a given redirect URL that starts with a slash ("/") as relative to the current ServletContext, i.e. as relative to the web application root. -
setRedirectHttp10Compatible
public void setRedirectHttp10Compatible(boolean redirectHttp10Compatible) Set whether redirects should stay compatible with HTTP 1.0 clients.In the default implementation, this will enforce HTTP status code 302 in any case, i.e. delegate to
HttpServletResponse.sendRedirect. Turning this off will send HTTP status code 303, which is the correct code for HTTP 1.1 clients, but not understood by HTTP 1.0 clients.Many HTTP 1.1 clients treat 302 just like 303, not making any difference. However, some clients depend on 303 when redirecting after a POST request; turn this flag off in such a scenario.
Redirect URLs can be specified via the "redirect:" prefix. E.g.: "redirect:myAction"
-
isRedirectHttp10Compatible
protected boolean isRedirectHttp10Compatible()Return whether redirects should stay compatible with HTTP 1.0 clients. -
setRequestContextAttribute
Set the name of the RequestContext attribute for all views.- 参数:
requestContextAttribute- name of the RequestContext attribute- 另请参阅:
-
getRequestContextAttribute
Return the name of the RequestContext attribute for all views, if any. -
setAttributes
Set static attributes from ajava.util.Propertiesobject, for all views returned by this resolver.This is the most convenient way to set static attributes. Note that static attributes can be overridden by dynamic attributes, if a value with the same name is included in the model.
Can be populated with a String "value" (parsed via PropertiesEditor) or a "props" element in XML bean definitions.
-
setAttributesMap
Set static attributes from a Map, for all views returned by this resolver. This allows to set any kind of attribute values, for example bean references.Can be populated with a "map" or "props" element in XML bean definitions.
- 参数:
attributes- a Map with name Strings as keys and attribute objects as values- 另请参阅:
-
getAttributesMap
Allow Map access to the static attributes for views returned by this resolver, with the option to add or override specific entries.Useful for specifying entries directly, for example via "attributesMap[myKey]". This is particularly useful for adding or overriding entries in child view definitions.
-
setExposePathVariables
Specify whether views resolved by this resolver should add path variables to the model or not.The default setting is to let each View decide (see
AbstractView.setExposePathVariables(boolean)). However, you can use this property to override that.- 参数:
exposePathVariables-true- all Views resolved by this resolver will expose path variablesfalse- no Views resolved by this resolver will expose path variablesnull- individual Views can decide for themselves (this is used by default)
- 另请参阅:
-
getExposePathVariables
Return whether views resolved by this resolver should add path variables to the model or not. -
setExposeContextBeansAsAttributes
public void setExposeContextBeansAsAttributes(boolean exposeContextBeansAsAttributes) Set whether to make all Framework beans in the application context accessible as request attributes, through lazy checking once an attribute gets accessed.This will make all such beans accessible in plain
${...}expressions in a JSP 2.0 page, as well as in JSTL'sc:outvalue expressions.Default is "false".
-
getExposeContextBeansAsAttributes
-
setExposedContextBeanNames
Specify the names of beans in the context which are supposed to be exposed. If this is non-null, only the specified beans are eligible for exposure as attributes. -
getExposedContextBeanNames
-
setViewNames
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
Return the view names (or name patterns) that can be handled by thisViewResolver. -
setExposeOutputRedirectModel
public void setExposeOutputRedirectModel(boolean exposeOutputRedirectModel) setexposeOutputRedirectModelto determine if all 'output' RedirectModel should be put into model- 参数:
exposeOutputRedirectModel- If true, all 'output' RedirectModel will be put to current view- 另请参阅:
-
setOrder
public void setOrder(int order) Specify the order value for this ViewResolver bean.The default value is
Ordered.LOWEST_PRECEDENCE, meaning non-ordered.- 另请参阅:
-
Ordered.getOrder()
-
getOrder
public int getOrder()- 指定者:
getOrder在接口中cn.taketoday.core.Ordered
-
initApplicationContext
protected void initApplicationContext()- 覆盖:
initApplicationContext在类中cn.taketoday.context.support.ApplicationObjectSupport
-
getCacheKey
This implementation returns just the view name, as this ViewResolver doesn't support localized resolution. -
createView
Overridden to implement check for "redirect:" prefix.Not possible in
loadView, since overriddenloadViewversions in subclasses might rely on the superclass always creating instances of the required view class.- 覆盖:
createView在类中AbstractCachingViewResolver- 参数:
viewName- the name of the view to retrievelocale- the Locale to retrieve the view for- 返回:
- the View instance, or
nullif not found (optional, to allow for ViewResolver chaining) - 抛出:
Exception- if the view couldn't be resolved- 另请参阅:
-
canHandle
Indicates whether or not thisViewResolvercan handle the supplied view name. If not,createView(String, Locale)will returnnull. 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
- 另请参阅:
-
StringUtils.simpleMatch(String, String)
-
requiredViewClass
Return the required type of view for this resolver. This implementation returnsAbstractUrlBasedView. -
instantiateView
Instantiate the specified view class.The default implementation uses reflection to instantiate the class.
- 返回:
- a new instance of the view class
- 另请参阅:
-
loadView
Delegates tobuildViewfor creating a new instance of the specified view class. Applies the following Framework lifecycle methods (as supported by the generic Framework bean factory):- ApplicationContextAware's
setApplicationContext - InitializingBean's
afterPropertiesSet
- 指定者:
loadView在类中AbstractCachingViewResolver- 参数:
viewName- the name of the view to retrievelocale- the Locale to retrieve the view for- 返回:
- the View instance
- 抛出:
Exception- if the view couldn't be resolved- 另请参阅:
-
buildView(String)ApplicationContextAware.setApplicationContext(cn.taketoday.context.ApplicationContext)InitializingBean.afterPropertiesSet()
- ApplicationContextAware's
-
buildView
Creates a new View instance of the specified view class and configures it. Does not perform any lookup for pre-defined View instances.Framework lifecycle methods as defined by the bean container do not have to be called here; those will be applied by the
loadViewmethod after this method returns.Subclasses will typically call
super.buildView(viewName)first, before setting further properties themselves.loadViewwill then apply Framework lifecycle methods at the end of this process.- 参数:
viewName- the name of the view to build- 返回:
- the View instance
- 抛出:
Exception- if the view couldn't be resolved- 另请参阅:
-
applyLifecycleMethods
Apply the containingApplicationContext's lifecycle methods to the givenViewinstance, if such a context is available.- 参数:
viewName- the name of the viewview- the freshly created View instance, pre-configured withAbstractUrlBasedView's properties- 返回:
- the
Viewinstance to use (either the original one or a decorated variant) - 另请参阅:
-
ApplicationObjectSupport.getApplicationContext()ApplicationContext.getAutowireCapableBeanFactory()AutowireCapableBeanFactory.initializeBean(java.lang.Object, java.lang.String)
-