Package org.springframework.web.accept
Class ParameterContentNegotiationStrategy
- java.lang.Object
- org.springframework.web.accept.MappingMediaTypeFileExtensionResolver
- org.springframework.web.accept.AbstractMappingContentNegotiationStrategy
- org.springframework.web.accept.ParameterContentNegotiationStrategy
- All Implemented Interfaces:
ContentNegotiationStrategy
,MediaTypeFileExtensionResolver
public class ParameterContentNegotiationStrategy extends AbstractMappingContentNegotiationStrategy
Strategy that resolves the requested content type from a query parameter. The default query parameter name is "format".You can register static mappings between keys (i.e. the expected value of the query parameter) and MediaType's via
MappingMediaTypeFileExtensionResolver.addMapping(String, MediaType)
. As of 5.0 this strategy also supports dynamic lookups of keys viaMediaTypeFactory.getMediaType(org.springframework.core.io.Resource)
.- Since:
- 3.2
- Author:
- Rossen Stoyanchev
Field Summary
Fields inherited from class org.springframework.web.accept.AbstractMappingContentNegotiationStrategy
logger
Fields inherited from interface org.springframework.web.accept.ContentNegotiationStrategy
MEDIA_TYPE_ALL_LIST
Constructor Summary
Constructors Constructor Description ParameterContentNegotiationStrategy(Map<String,MediaType> mediaTypes)
Create an instance with the given map of file extensions and media types.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
getMediaTypeKey(NativeWebRequest request)
Extract a key from the request to use to look up media types.String
getParameterName()
void
setParameterName(String parameterName)
Set the name of the parameter to use to determine requested media types.Methods inherited from class org.springframework.web.accept.AbstractMappingContentNegotiationStrategy
handleMatch, handleNoMatch, isIgnoreUnknownExtensions, isUseRegisteredExtensionsOnly, resolveMediaTypeKey, resolveMediaTypes, setIgnoreUnknownExtensions, setUseRegisteredExtensionsOnly
Methods inherited from class org.springframework.web.accept.MappingMediaTypeFileExtensionResolver
addMapping, getAllFileExtensions, getAllMediaTypes, getMediaTypes, lookupMediaType, resolveFileExtensions
Constructor Detail
ParameterContentNegotiationStrategy
public ParameterContentNegotiationStrategy(Map<String,MediaType> mediaTypes)
Create an instance with the given map of file extensions and media types.
Method Detail
setParameterName
public void setParameterName(String parameterName)
Set the name of the parameter to use to determine requested media types.By default this is set to
"format"
.
getParameterName
public String getParameterName()
getMediaTypeKey
@Nullable protected String getMediaTypeKey(NativeWebRequest request)
Description copied from class:AbstractMappingContentNegotiationStrategy
Extract a key from the request to use to look up media types.- Specified by:
getMediaTypeKey
in classAbstractMappingContentNegotiationStrategy
- Returns:
- the lookup key, or
null
if none