类 ContentNegotiationManagerFactoryBean
- 所有已实现的接口:
cn.taketoday.beans.factory.FactoryBean<ContentNegotiationManager>,cn.taketoday.beans.factory.InitializingBean
ContentNegotiationManager and configure it with
ContentNegotiationStrategy instances.
This factory offers properties that in turn result in configuring the underlying strategies. The table below shows the property names, their default settings, as well as the strategies that they help to configure:
| Property Setter | Default Value | Underlying Strategy | Enabled Or Not |
|---|---|---|---|
favorParameter |
false | ParameterContentNegotiationStrategy |
Off |
ignoreAcceptHeader |
false | HeaderContentNegotiationStrategy |
Enabled |
favorPathExtension |
false | PathExtensionContentNegotiationStrategy |
Off |
defaultContentType |
null | FixedContentNegotiationStrategy |
Off |
defaultContentTypeStrategy |
null | ContentNegotiationStrategy |
Off |
Alternatively you can avoid use of the above convenience builder
methods and set the exact strategies to use via
setStrategies(List).
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Brian Clozel, Harry Yang
-
字段概要
字段修饰符和类型字段说明private ContentNegotiationManagerprivate ContentNegotiationStrategyprivate booleanprivate booleanprivate booleanprivate booleanprivate Stringprivate Objectprivate List<ContentNegotiationStrategy>private Boolean从接口继承的字段 cn.taketoday.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidaddMediaType(String key, MediaType mediaType) An alternative tosetMediaTypes(java.util.Properties)for programmatic registrations.voidaddMediaTypes(Map<String, MediaType> mediaTypes) An alternative tosetMediaTypes(java.util.Properties)for programmatic registrations.voidbuild()Create and initialize aContentNegotiationManagerinstance.Class<?>booleanvoidsetDefaultContentType(MediaType contentType) Set the default content type to use when no content type is requested.voidsetDefaultContentTypes(List<MediaType> contentTypes) Set the default content types to use when no content type is requested.voidSet a customContentNegotiationStrategyto use to determine the content type to use when no content type is requested.voidsetFavorParameter(boolean favorParameter) Whether a request parameter ("format" by default) should be used to determine the requested media type.voidsetFavorPathExtension(boolean favorPathExtension) Whether the path extension in the URL path should be used to determine the requested media type.voidsetIgnoreAcceptHeader(boolean ignoreAcceptHeader) Whether to disable checking the 'Accept' request header.voidsetIgnoreUnknownPathExtensions(boolean ignore) Whether to ignore requests with path extension that cannot be resolved to any media type.voidsetMediaTypes(Properties mediaTypes) Add a mapping from a key to a MediaType where the key are normalized to lowercase and may have been extracted from a path extension, a filename extension, or passed as a query parameter.voidsetParameterName(String parameterName) Set the query parameter name to use whensetFavorParameter(boolean)is on.voidsetServletContext(Object servletContext) voidsetStrategies(List<ContentNegotiationStrategy> strategies) Set the exact list of strategies to use.voidsetUseRegisteredExtensionsOnly(boolean useRegisteredExtensionsOnly) WhensetFavorParameter(boolean)is set, this property determines whether to use only registeredMediaTypemappings or to allow dynamic resolution, e.g. viaMediaType.fromFileName(String)MediaTypeFactory}.
-
字段详细资料
-
strategies
-
favorParameter
private boolean favorParameter -
parameterName
-
ignoreUnknownPathExtensions
private boolean ignoreUnknownPathExtensions -
favorPathExtension
private boolean favorPathExtension -
mediaTypes
-
useRegisteredExtensionsOnly
-
ignoreAcceptHeader
private boolean ignoreAcceptHeader -
defaultNegotiationStrategy
-
contentNegotiationManager
-
servletContext
-
-
构造器详细资料
-
ContentNegotiationManagerFactoryBean
public ContentNegotiationManagerFactoryBean()
-
-
方法详细资料
-
setStrategies
Set the exact list of strategies to use.Note: use of this method is mutually exclusive with use of all other setters in this class which customize a default, fixed set of strategies. See class level doc for more details.
- 参数:
strategies- the strategies to use
-
setFavorParameter
public void setFavorParameter(boolean favorParameter) Whether a request parameter ("format" by default) should be used to determine the requested media type. For this option to work you must registermedia type mappings.By default this is set to
false. -
setParameterName
Set the query parameter name to use whensetFavorParameter(boolean)is on.The default parameter name is
"format". -
setFavorPathExtension
public void setFavorPathExtension(boolean favorPathExtension) Whether the path extension in the URL path should be used to determine the requested media type.By default this is set to
falsein which case path extensions have no impact on content negotiation. -
setMediaTypes
Add a mapping from a key to a MediaType where the key are normalized to lowercase and may have been extracted from a path extension, a filename extension, or passed as a query parameter.The
parameter strategyrequires such mappings in order to work while the path extension strategy can fall back on lookups via andMediaType.Note: Mappings registered here may be accessed via
ContentNegotiationManager.getMediaTypeMappings()and may be used not only in the parameter and path extension strategies.- 参数:
mediaTypes- media type mappings- 另请参阅:
-
addMediaType
An alternative tosetMediaTypes(java.util.Properties)for programmatic registrations. -
addMediaTypes
An alternative tosetMediaTypes(java.util.Properties)for programmatic registrations. -
setIgnoreUnknownPathExtensions
public void setIgnoreUnknownPathExtensions(boolean ignore) Whether to ignore requests with path extension that cannot be resolved to any media type. Setting this tofalsewill result in anHttpMediaTypeNotAcceptableExceptionif there is no match.By default this is set to
true. -
setUseRegisteredExtensionsOnly
public void setUseRegisteredExtensionsOnly(boolean useRegisteredExtensionsOnly) WhensetFavorParameter(boolean)is set, this property determines whether to use only registeredMediaTypemappings or to allow dynamic resolution, e.g. viaMediaType.fromFileName(String)MediaTypeFactory}.By default this is not set in which case dynamic resolution is on.
-
setIgnoreAcceptHeader
public void setIgnoreAcceptHeader(boolean ignoreAcceptHeader) Whether to disable checking the 'Accept' request header.By default this value is set to
false. -
setDefaultContentType
Set the default content type to use when no content type is requested.By default this is not set.
-
setDefaultContentTypes
Set the default content types to use when no content type is requested.By default this is not set.
-
setDefaultContentTypeStrategy
Set a customContentNegotiationStrategyto use to determine the content type to use when no content type is requested.By default this is not set.
-
setServletContext
-
afterPropertiesSet
public void afterPropertiesSet()- 指定者:
afterPropertiesSet在接口中cn.taketoday.beans.factory.InitializingBean
-
build
Create and initialize aContentNegotiationManagerinstance. -
getObject
- 指定者:
getObject在接口中cn.taketoday.beans.factory.FactoryBean<ContentNegotiationManager>
-
getObjectType
- 指定者:
getObjectType在接口中cn.taketoday.beans.factory.FactoryBean<ContentNegotiationManager>
-
isSingleton
public boolean isSingleton()- 指定者:
isSingleton在接口中cn.taketoday.beans.factory.FactoryBean<ContentNegotiationManager>
-