Spring MVC中的多个内容类型 [英] Multiple Content-type in Spring MVC
问题描述
Spring MVC请求标头中可以有多个内容类型吗? 我要通过:
Can we have multiple content-type in Spring MVC request header? I'm passing:
{Content-type = application/json, text/plain}
通过邮递员到我的API.目前,我正在org.springframework.web.HttpMediaTypeNotSupportedException: Invalid mime type ....
through Postman to my API. Currently, I'm getting org.springframework.web.HttpMediaTypeNotSupportedException: Invalid mime type ....
我想知道,我的输入值中是否包含某些内容,或者我们的标题中不能包含多个content-type.
I wanted to know, is there something with my input values, or we can't have multiple content-type in our header.
Controller:
@RequestMapping(值="/地址",产生= APPLICATION_JSON_UTF8_VALUE,方法= GET)
@RequestMapping(value = "/addressees", produces = APPLICATION_JSON_UTF8_VALUE, method = GET)
推荐答案
是的,spring mvc请求映射支持多种类型的MIME类型,示例如下:
Yes, spring mvc request mapping supports multiple consumes MIME type , sample looks like
@RequestMapping(value = "/something", method = PUT,
consumes = {APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE},
produces = {APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE})
public SomeObject updateSomeObject(SomeObject acct) {
return doStuff(acct);
}
添加消耗了请求映射中的一部分,例如- consums = {APPLICATION_JSON_VALUE,APPLICATION_XML_VALUE}
Add consumes part in requestmapping like - consumes = {APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE}
要了解更多信息,请参考此链接-
For know more, refer this link -
这篇关于Spring MVC中的多个内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!