类 ContentNegotiationConfigurer
ContentNegotiationManager and configures it with
one or more 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(boolean) |
false | ParameterContentNegotiationStrategy |
Off |
ignoreAcceptHeader(boolean) |
false | HeaderContentNegotiationStrategy |
Enabled |
defaultContentType(cn.taketoday.http.MediaType...) |
null | FixedContentNegotiationStrategy |
Off |
defaultContentTypeStrategy(cn.taketoday.web.accept.ContentNegotiationStrategy) |
null | ContentNegotiationStrategy |
Off |
you can set the exact strategies to use via
strategies(List).
- 从以下版本开始:
- 4.0 2022/1/28 16:10
- 作者:
- Rossen Stoyanchev, Harry Yang
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected ContentNegotiationManagerBuild aContentNegotiationManagerbased on this configurer's settings.defaultContentType(MediaType... defaultContentTypes) Set the default content type(s) to use when no content type is requested in order of priority.defaultContentTypeStrategy(ContentNegotiationStrategy defaultStrategy) Set a customContentNegotiationStrategyto use to determine the content type to use when no content type is requested.favorParameter(boolean favorParameter) Whether a request parameter ("format" by default) should be used to determine the requested media type.ignoreAcceptHeader(boolean ignoreAcceptHeader) Whether to disable checking the 'Accept' request header.Add a mapping from a key, extracted from a path extension or a query parameter, to a MediaType.mediaTypes(Map<String, MediaType> mediaTypes) An alternative tomediaType(java.lang.String, cn.taketoday.http.MediaType).parameterName(String parameterName) Set the query parameter name to use whenfavorParameter(boolean)is on.replaceMediaTypes(Map<String, MediaType> mediaTypes) Similar tomediaType(java.lang.String, cn.taketoday.http.MediaType)but for replacing existing mappings.voidstrategies(List<ContentNegotiationStrategy> strategies) Set the exact list of strategies to use.useRegisteredExtensionsOnly(boolean useRegisteredExtensionsOnly) this property determines whether to use only registeredMediaTypemappings to resolve a path extension to a specific MediaType.
-
字段详细资料
-
factory
-
mediaTypes
-
-
构造器详细资料
-
ContentNegotiationConfigurer
public ContentNegotiationConfigurer() -
ContentNegotiationConfigurer
-
-
方法详细资料
-
strategies
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
-
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.- 另请参阅:
-
parameterName
Set the query parameter name to use whenfavorParameter(boolean)is on.The default parameter name is
"format". -
mediaType
Add a mapping from a key, extracted from a path extension or a query parameter, to a MediaType. This is required in order for the parameter strategy to work. Any extensions explicitly registered here are also treated as safe for the purpose of Reflected File Download attack detection.The path extension strategy will also try to use
ServletContext.getMimeType(java.lang.String)andMediaType.fromFileName(String)to resolve path extensions. To change this behavior see theuseRegisteredExtensionsOnly(boolean)property.- 参数:
extension- the key to look upmediaType- the media type- 另请参阅:
-
mediaTypes
An alternative tomediaType(java.lang.String, cn.taketoday.http.MediaType). -
replaceMediaTypes
Similar tomediaType(java.lang.String, cn.taketoday.http.MediaType)but for replacing existing mappings. -
useRegisteredExtensionsOnly
public ContentNegotiationConfigurer useRegisteredExtensionsOnly(boolean useRegisteredExtensionsOnly) this property determines whether to use only registeredMediaTypemappings to resolve a path extension to a specific MediaType. -
ignoreAcceptHeader
Whether to disable checking the 'Accept' request header.By default this value is set to
false. -
defaultContentType
Set the default content type(s) to use when no content type is requested in order of priority.If destinations are present that do not support any of the given media types, consider appending
MediaType.ALLat the end.By default this is not set.
-
defaultContentTypeStrategy
public ContentNegotiationConfigurer defaultContentTypeStrategy(ContentNegotiationStrategy defaultStrategy) Set a customContentNegotiationStrategyto use to determine the content type to use when no content type is requested.By default this is not set.
-
buildContentNegotiationManager
Build aContentNegotiationManagerbased on this configurer's settings.
-