类 PathExtensionContentNegotiationStrategy
- java.lang.Object
- org.springframework.web.accept.MappingMediaTypeFileExtensionResolver
- org.springframework.web.accept.AbstractMappingContentNegotiationStrategy
- org.springframework.web.accept.PathExtensionContentNegotiationStrategy
public class PathExtensionContentNegotiationStrategy extends AbstractMappingContentNegotiationStrategy
AContentNegotiationStrategy
that resolves the file extension in the request path to a key to be used to look up a media type.If the file extension is not found in the explicit registrations provided to the constructor, the Java Activation Framework (JAF) is used as a fallback mechanism.
The presence of the JAF is detected and enabled automatically but the
setUseJaf(boolean)
property may be set to false.- 从以下版本开始:
- 3.2
- 作者:
- Rossen Stoyanchev
构造器概要
构造器 构造器 说明 PathExtensionContentNegotiationStrategy()
Create an instance without any mappings to start with.PathExtensionContentNegotiationStrategy(Map<String,MediaType> mediaTypes)
Create an instance with the given map of file extensions and media types.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 MediaType
getMediaTypeForResource(Resource resource)
protected String
getMediaTypeKey(NativeWebRequest webRequest)
Extract a key from the request to use to look up media types.protected MediaType
handleNoMatch(NativeWebRequest webRequest, String extension)
Override to provide handling when a key is not resolved via.void
setIgnoreUnknownExtensions(boolean ignoreUnknownExtensions)
Whether to ignore requests with unknown file extension.void
setUrlPathHelper(UrlPathHelper urlPathHelper)
Configure aUrlPathHelper
to use ingetMediaTypeKey(org.springframework.web.context.request.NativeWebRequest)
in order to derive the lookup path for a target request URL path.void
setUseJaf(boolean useJaf)
Whether to use the Java Activation Framework to look up file extensions.从类继承的方法 org.springframework.web.accept.AbstractMappingContentNegotiationStrategy
handleMatch, resolveMediaTypeKey, resolveMediaTypes
从类继承的方法 org.springframework.web.accept.MappingMediaTypeFileExtensionResolver
addMapping, getAllFileExtensions, getAllMediaTypes, getMediaTypes, lookupMediaType, resolveFileExtensions
构造器详细资料
PathExtensionContentNegotiationStrategy
public PathExtensionContentNegotiationStrategy()
Create an instance without any mappings to start with. Mappings may be added later on if any extensions are resolved through the Java Activation framework.
PathExtensionContentNegotiationStrategy
public PathExtensionContentNegotiationStrategy(Map<String,MediaType> mediaTypes)
Create an instance with the given map of file extensions and media types.
方法详细资料
setUrlPathHelper
public void setUrlPathHelper(UrlPathHelper urlPathHelper)
Configure aUrlPathHelper
to use ingetMediaTypeKey(org.springframework.web.context.request.NativeWebRequest)
in order to derive the lookup path for a target request URL path.- 从以下版本开始:
- 4.2.8
setUseJaf
public void setUseJaf(boolean useJaf)
Whether to use the Java Activation Framework to look up file extensions.By default this is set to "true" but depends on JAF being present.
setIgnoreUnknownExtensions
public void setIgnoreUnknownExtensions(boolean ignoreUnknownExtensions)
Whether to ignore requests with unknown file extension. Setting this tofalse
results inHttpMediaTypeNotAcceptableException
.By default this is set to
true
.
getMediaTypeKey
protected String getMediaTypeKey(NativeWebRequest webRequest)
Extract a key from the request to use to look up media types.- 指定者:
getMediaTypeKey
在类中AbstractMappingContentNegotiationStrategy
- 返回:
- the lookup key, or
null
if none
handleNoMatch
protected MediaType handleNoMatch(NativeWebRequest webRequest, String extension) throws HttpMediaTypeNotAcceptableException
Override to provide handling when a key is not resolved via.MappingMediaTypeFileExtensionResolver.lookupMediaType(java.lang.String)
. Sub-classes can take further steps to determine the media type(s). If a MediaType is returned from this method it will be added to the cache in the base class.
getMediaTypeForResource
public MediaType getMediaTypeForResource(Resource resource)
A public method exposing the knowledge of the path extension strategy to resolve file extensions to aMediaType
in this case for a givenResource
. The method first looks up any explicitly registered file extensions first and then falls back on JAF if available.- 参数:
resource
- the resource to look up- 返回:
- the MediaType for the extension, or
null
if none found - 从以下版本开始:
- 4.3