本文整理汇总了Java中org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer类的典型用法代码示例。如果您正苦于以下问题:Java ContentNegotiationConfigurer类的具体用法?Java ContentNegotiationConfigurer怎么用?Java ContentNegotiationConfigurer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContentNegotiationConfigurer类属于org.springframework.web.servlet.config.annotation包,在下文中一共展示了ContentNegotiationConfigurer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
/**
* Allows the use of the format query parameter to be used
* instead of the Accept HTTP header
*/
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorParameter(true)
// Browser
.mediaType("html", MediaType.TEXT_HTML)
// API
.mediaType("json", MediaType.APPLICATION_JSON)
// RDF
.mediaType("turtle", parseMediaType("text/turtle"))
.mediaType("jsonld", parseMediaType("application/ld+json"))
.mediaType("rdfxml", parseMediaType("application/rdf+xml"))
// Images
.mediaType("svg", parseMediaType("image/svg+xml"))
.mediaType("png", MediaType.IMAGE_PNG)
.mediaType("dot", parseMediaType("text/vnd+graphviz"))
// Archives
.mediaType("zip", parseMediaType("application/zip"))
.mediaType("ro", parseMediaType("application/vnd.wf4ever.robundle+zip"))
// raw redirects
.mediaType("yaml", parseMediaType("text/x-yaml"))
.mediaType("raw", MediaType.APPLICATION_OCTET_STREAM);
}
示例2: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer
.favorPathExtension(false)
.favorParameter(true)
.parameterName("mimeType")
.mediaType(csv.getExtension(), csv.mediaType)
.mediaType(tsv.getExtension(), tsv.mediaType)
.mediaType(xml.getExtension(), xml.mediaType)
.mediaType(json.getExtension(), json.mediaType)
.mediaType(xlsx.getExtension(), xlsx.mediaType)
.mediaType(kml.getExtension(), kml.mediaType)
.mediaType(kmz.getExtension(), kmz.mediaType)
.mediaType(geojson.getExtension(), geojson.mediaType)
.mediaType(text.getExtension(), text.mediaType)
;
}
示例3: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer cfg) {
cfg.favorParameter(false) // disable 'resource?format=xxx'
.favorPathExtension(false) // disable 'resource.xxx'
.ignoreAcceptHeader(false) // use Accept header
.defaultContentType(MediaType.TEXT_PLAIN); // (*)
}
示例4: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
@Override
public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false).
favorParameter(true).
parameterName("mediaType").
ignoreAcceptHeader(true).
useJaf(false).
defaultContentType(MediaType.APPLICATION_JSON).
mediaType("xml", MediaType.APPLICATION_XML).
mediaType("json", MediaType.APPLICATION_JSON);
}
示例5: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.mediaType("adoc", MediaType.parseMediaType("text/asciidoc;charset=utf-8"))
.mediaType("md", MediaType.parseMediaType("text/markdown;charset=utf-8"))
.mediaType("html", MediaType.parseMediaType("text/html;charset=utf-8"))
.mediaType("properties", MediaType.parseMediaType("text/properties;charset=utf-8"))
.mediaType("yml", MediaType.parseMediaType("text/yaml;charset=utf-8"))
.mediaType("sql", MediaType.parseMediaType(MediaType.TEXT_PLAIN_VALUE + ";charset=utf-8"))
.mediaType("jdl", MediaType.parseMediaType(MediaType.TEXT_PLAIN_VALUE + ";charset=utf-8"))
.mediaType("doc", MediaType.parseMediaType("application/msword"));
super.configureContentNegotiation(configurer);
}
示例6: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
/**
* Setup a simple strategy: use all the defaults and return JSON by default when not sure.
*/
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.APPLICATION_JSON_UTF8).
mediaType("xml", MediaType.APPLICATION_JSON_UTF8).
mediaType("json", MediaType.APPLICATION_JSON);
}
示例7: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.ignoreAcceptHeader(true)
.favorParameter(true)
.ignoreUnknownPathExtensions(false)
.defaultContentType(OntologySyntax.RDF_XML.getMediaType())
.mediaType("owx", OntologySyntax.OWL_XML.getMediaType())
.mediaType("owl", OntologySyntax.RDF_XML.getMediaType())
.mediaType("rdf", OntologySyntax.RDF_XML.getMediaType())
.mediaType("xml", OntologySyntax.RDF_XML.getMediaType())
.mediaType("ofn", OntologySyntax.FUNCTIONAL.getMediaType())
.mediaType("omn", OntologySyntax.MANCHESTER.getMediaType())
.mediaType("ttl", OntologySyntax.TURTLE.getMediaType());
}
示例8: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.TEXT_HTML);
for (Type value : Type.values()) {
configurer.mediaType(value.getExtension(), value.getMediaType());
}
}
示例9: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false)
.favorParameter(true)
.parameterName("format")
.ignoreAcceptHeader(true)
.useJaf(false)
.defaultContentType(MediaType.APPLICATION_JSON)
.mediaType("json", MediaType.APPLICATION_JSON);
}
示例10: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
/**
* Spring 3.2 及以上版本自动开启检测URL后缀,设置Response content-type功能, 如果不手动关闭这个功能,当url后缀与accept头不一致时,
* Response的content-type将会和request的accept不一致,导致报 406 错误
* 例如返回类型为 JSON 的 @ResponseBody API, 必须将请求URL后缀改为.json,以便和 accept头(application/json)相匹配,否则返回 406 错误。
*/
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false). //关闭URL后缀检测的方法如下
favorParameter(true).
mediaType("json", MediaType.APPLICATION_JSON).
defaultContentType(MediaType.APPLICATION_JSON);//如果没有对应的后缀名,返回信息默认以 json 格式返回
}
示例11: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
/**
* Spring 3.2 及以上版本自动开启检测URL后缀,设置Response content-type功能, 如果不手动关闭这个功能,当url后缀与accept头不一致时,
* Response的content-type将会和request的accept不一致,导致报 406 错误
* 例如返回类型为 JSON 的 @ResponseBody API, 必须将请求URL后缀改为.json,以便和 accept头(application/json)相匹配,否则返回 406 错误。
*/
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false). //关闭URL后缀检测的方法如下
favorParameter(true).
parameterName("mediaType").
ignoreAcceptHeader(true).
useJaf(false).
mediaType("xml", MediaType.APPLICATION_XML).
mediaType("json", MediaType.APPLICATION_JSON).
defaultContentType(MediaType.APPLICATION_JSON);//如果没有对应的后缀名,返回信息默认以 json 格式返回
}
示例12: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
Map<String, MediaType> mediaTypes = this.mvcProperties.getMediaTypes();
for (Entry<String, MediaType> mediaType : mediaTypes.entrySet()) {
configurer.mediaType(mediaType.getKey(), mediaType.getValue());
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:WebMvcAutoConfiguration.java
示例13: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer
.defaultContentType(MediaType.TEXT_HTML)
.mediaType("html", MediaType.TEXT_HTML)
.mediaType("xml", MediaType.APPLICATION_XML)
.mediaType("json", MediaType.APPLICATION_JSON)
.favorPathExtension(true)
.favorParameter(true)
.parameterName("mediaType")
.ignoreAcceptHeader(false);
}
示例14: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(false).
favorParameter(true).
parameterName("mediaType").
ignoreAcceptHeader(true).
useJaf(false).
defaultContentType(MediaType.APPLICATION_JSON).
mediaType("xml", MediaType.APPLICATION_XML).
mediaType("json", MediaType.APPLICATION_JSON);
}
示例15: configureContentNegotiation
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; //导入依赖的package包/类
/**
* Visitor method to configure content negotiation for this converter.
* @param configurer {@link WebMvcConfigurerAdapter#configureContentNegotiation(ContentNegotiationConfigurer)
* WebMvcConfigurerAdapter} configurer instance.
*/
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.mediaType(format.getDefaultFileExtension(),
MediaType.parseMediaType(format.getDefaultMIMEType()));
LOGGER.info("registering {} with {}", format.getDefaultFileExtension(),
format.getDefaultMIMEType());
}