Spring MVC @RequestMapping标头只能接受一个值吗? [英] Spring MVC @RequestMapping headers can accept only one value?

查看:488
本文介绍了Spring MVC @RequestMapping标头只能接受一个值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这样可行:

@RequestMapping(value = "/test", method = RequestMethod.POST,
    headers = {"content-type=application/json"}) {
    .......
}

如果我像下面那样添加另一个值,那么它将失败并告诉我:

If I add another value to it like the following, then it will fail and tell me this:


请求的资源不允许使用指定的HTTP方法
(不支持请求方法'POST')

The specified HTTP method is not allowed for the requested resource (Request method 'POST' not supported)



@RequestMapping(value = "/test", method = RequestMethod.POST,
    headers = {"content-type=application/json","content-type=application/xml"}) {
    .......
}

< br>
我想这是因为Spring认为两个内容类型值具有AND关系,但我希望它们是OR。


I guess this is because Spring thinks the two content type values have "AND" relationship but instead I want them to be "OR".

有什么建议吗?

谢谢!

推荐答案

你有没有试过 content-type = application / json,application / xml

不确定它是否可行但放两个内容类型标题我认为只有一个会赢。

Not sure if it would work but putting two content-type headers in there I think only one will win.

OR

可能在同一方法上使用两个 RequestMapping 注释,使用不同的内容类型标题?

possibily use two RequestMapping annotations on the same method with different content-type headers?

这篇关于Spring MVC @RequestMapping标头只能接受一个值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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