类 DefaultRequestToViewNameTranslator
- java.lang.Object
- org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator
- 所有已实现的接口:
RequestToViewNameTranslator
public class DefaultRequestToViewNameTranslator extends Object implements RequestToViewNameTranslator
RequestToViewNameTranslator
that simply transforms the URI of the incoming request into a view name.Can be explicitly defined as the
viewNameTranslator
bean in aDispatcherServlet
context. Otherwise, a plain default instance will be used.The default transformation simply strips leading and trailing slashes as well as the file extension of the URI, and returns the result as the view name with the configured
prefix
and asuffix
added as appropriate.The stripping of the leading slash and file extension can be disabled using the
stripLeadingSlash
andstripExtension
properties, respectively.Find below some examples of request to view name translation.
http://localhost:8080/gamecast/display.html
»display
http://localhost:8080/gamecast/displayShoppingCart.html
»displayShoppingCart
http://localhost:8080/gamecast/admin/index.html
»admin/index
- 从以下版本开始:
- 2.0
- 作者:
- Rob Harrop, Juergen Hoeller
- 另请参阅:
RequestToViewNameTranslator
,ViewResolver
构造器概要
构造器 构造器 说明 DefaultRequestToViewNameTranslator()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 String
getViewName(HttpServletRequest request)
Translates the request URI of the incomingHttpServletRequest
into the view name based on the configured parameters.void
setAlwaysUseFullPath(boolean alwaysUseFullPath)
Shortcut to same property on underlyingUrlPathHelper
.void
setPrefix(String prefix)
Set the prefix to prepend to generated view names.void
setRemoveSemicolonContent(boolean removeSemicolonContent)
Set if ";" (semicolon) content should be stripped from the request URI.void
setSeparator(String separator)
Set the value that will replace '/
' as the separator in the view name.void
setStripExtension(boolean stripExtension)
Set whether or not file extensions should be stripped from the URI when generating the view name.void
setStripLeadingSlash(boolean stripLeadingSlash)
Set whether or not leading slashes should be stripped from the URI when generating the view name.void
setStripTrailingSlash(boolean stripTrailingSlash)
Set whether or not trailing slashes should be stripped from the URI when generating the view name.void
setSuffix(String suffix)
Set the suffix to append to generated view names.void
setUrlDecode(boolean urlDecode)
Shortcut to same property on underlyingUrlPathHelper
.void
setUrlPathHelper(UrlPathHelper urlPathHelper)
Set theUrlPathHelper
to use for the resolution of lookup paths.protected String
transformPath(String lookupPath)
Transform the request URI (in the context of the webapp) stripping slashes and extensions, and replacing the separator as required.
构造器详细资料
DefaultRequestToViewNameTranslator
public DefaultRequestToViewNameTranslator()
方法详细资料
setPrefix
public void setPrefix(@Nullable String prefix)
Set the prefix to prepend to generated view names.- 参数:
prefix
- the prefix to prepend to generated view names
setSuffix
public void setSuffix(@Nullable String suffix)
Set the suffix to append to generated view names.- 参数:
suffix
- the suffix to append to generated view names
setSeparator
public void setSeparator(String separator)
Set the value that will replace '/
' as the separator in the view name. The default behavior simply leaves '/
' as the separator.
setStripLeadingSlash
public void setStripLeadingSlash(boolean stripLeadingSlash)
Set whether or not leading slashes should be stripped from the URI when generating the view name. Default is "true".
setStripTrailingSlash
public void setStripTrailingSlash(boolean stripTrailingSlash)
Set whether or not trailing slashes should be stripped from the URI when generating the view name. Default is "true".
setStripExtension
public void setStripExtension(boolean stripExtension)
Set whether or not file extensions should be stripped from the URI when generating the view name. Default is "true".
setAlwaysUseFullPath
public void setAlwaysUseFullPath(boolean alwaysUseFullPath)
Shortcut to same property on underlyingUrlPathHelper
.
setUrlDecode
public void setUrlDecode(boolean urlDecode)
Shortcut to same property on underlyingUrlPathHelper
.
setRemoveSemicolonContent
public void setRemoveSemicolonContent(boolean removeSemicolonContent)
Set if ";" (semicolon) content should be stripped from the request URI.
setUrlPathHelper
public void setUrlPathHelper(UrlPathHelper urlPathHelper)
Set theUrlPathHelper
to use for the resolution of lookup paths.Use this to override the default UrlPathHelper with a custom subclass, or to share common UrlPathHelper settings across multiple web components.
getViewName
public String getViewName(HttpServletRequest request)
Translates the request URI of the incomingHttpServletRequest
into the view name based on the configured parameters.- 指定者:
getViewName
在接口中RequestToViewNameTranslator
- 参数:
request
- the incomingHttpServletRequest
providing the context from which a view name is to be resolved- 返回:
- the view name, or
null
if no default found - 另请参阅:
UrlPathHelper.getLookupPathForRequest(javax.servlet.http.HttpServletRequest)
,transformPath(java.lang.String)
transformPath
@Nullable protected String transformPath(String lookupPath)
Transform the request URI (in the context of the webapp) stripping slashes and extensions, and replacing the separator as required.- 参数:
lookupPath
- the lookup path for the current request, as determined by the UrlPathHelper- 返回:
- the transformed path, with slashes and extensions stripped if desired