本文整理匯總了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());
}