Spring MVC中的多个内容类型 [英] Multiple Content-type in Spring MVC

查看:65
本文介绍了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 -

https ://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html

这篇关于Spring MVC中的多个内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆