类 ContentNegotiationManager
- java.lang.Object
- org.springframework.web.accept.ContentNegotiationManager
public class ContentNegotiationManager extends Object implements ContentNegotiationStrategy, MediaTypeFileExtensionResolver
Central class to determine requested media types for a request. This is done by delegating to a list of configuredContentNegotiationStrategyinstances.Also provides methods to look up file extensions for a media type. This is done by delegating to the list of configured
MediaTypeFileExtensionResolverinstances.- 从以下版本开始:
- 3.2
- 作者:
- Rossen Stoyanchev, Juergen Hoeller
构造器概要
构造器 构造器 说明 ContentNegotiationManager()Create a default instance with aHeaderContentNegotiationStrategy.ContentNegotiationManager(Collection<ContentNegotiationStrategy> strategies)A collection-based alternative toContentNegotiationManager(ContentNegotiationStrategy...).ContentNegotiationManager(ContentNegotiationStrategy... strategies)Create an instance with the given list ofContentNegotiationStrategystrategies each of which may also be an instance ofMediaTypeFileExtensionResolver.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidaddFileExtensionResolvers(MediaTypeFileExtensionResolver... resolvers)Register moreMediaTypeFileExtensionResolverinstances in addition to those detected at construction.List<String>getAllFileExtensions()Return all registered file extensions.List<ContentNegotiationStrategy>getStrategies()Return the configured content negotiation strategies.<T extends ContentNegotiationStrategy>
TgetStrategy(Class<T> strategyType)Find aContentNegotiationStrategyof the given type.List<String>resolveFileExtensions(MediaType mediaType)Resolve the given media type to a list of path extensions.List<MediaType>resolveMediaTypes(NativeWebRequest request)Resolve the given request to a list of media types.
构造器详细资料
ContentNegotiationManager
public ContentNegotiationManager(ContentNegotiationStrategy... strategies)
Create an instance with the given list ofContentNegotiationStrategystrategies each of which may also be an instance ofMediaTypeFileExtensionResolver.- 参数:
strategies- the strategies to use
ContentNegotiationManager
public ContentNegotiationManager(Collection<ContentNegotiationStrategy> strategies)
A collection-based alternative toContentNegotiationManager(ContentNegotiationStrategy...).- 参数:
strategies- the strategies to use- 从以下版本开始:
- 3.2.2
ContentNegotiationManager
public ContentNegotiationManager()
Create a default instance with aHeaderContentNegotiationStrategy.
方法详细资料
getStrategies
public List<ContentNegotiationStrategy> getStrategies()
Return the configured content negotiation strategies.- 从以下版本开始:
- 3.2.16
getStrategy
public <T extends ContentNegotiationStrategy> T getStrategy(Class<T> strategyType)
Find aContentNegotiationStrategyof the given type.- 参数:
strategyType- the strategy type- 返回:
- the first matching strategy, or
nullif none - 从以下版本开始:
- 4.3
addFileExtensionResolvers
public void addFileExtensionResolvers(MediaTypeFileExtensionResolver... resolvers)
Register moreMediaTypeFileExtensionResolverinstances in addition to those detected at construction.- 参数:
resolvers- the resolvers to add
resolveMediaTypes
public List<MediaType> resolveMediaTypes(NativeWebRequest request) throws HttpMediaTypeNotAcceptableException
从接口复制的说明:ContentNegotiationStrategyResolve the given request to a list of media types. The returned list is ordered by specificity first and by quality parameter second.- 指定者:
resolveMediaTypes在接口中ContentNegotiationStrategy- 参数:
request- the current request- 返回:
- the requested media types or an empty list (never
null) - 抛出:
HttpMediaTypeNotAcceptableException- if the requested media types cannot be parsed
resolveFileExtensions
public List<String> resolveFileExtensions(MediaType mediaType)
从接口复制的说明:MediaTypeFileExtensionResolverResolve the given media type to a list of path extensions.- 指定者:
resolveFileExtensions在接口中MediaTypeFileExtensionResolver- 参数:
mediaType- the media type to resolve- 返回:
- a list of extensions or an empty list (never
null)
getAllFileExtensions
public List<String> getAllFileExtensions()
Return all registered file extensions.At startup this method returns extensions explicitly registered with either
PathExtensionContentNegotiationStrategyorParameterContentNegotiationStrategy. At runtime if there is a "path extension" strategy and itsuseJafproperty is set to "true", the list of extensions may increase as file extensions are resolved via JAF and cached.- 指定者:
getAllFileExtensions在接口中MediaTypeFileExtensionResolver- 返回:
- a list of extensions or an empty list (never
null)