Spring MVC @RequestMapping标头只能接受一个值吗? [英] Spring MVC @RequestMapping headers can accept only one value?
问题描述
这样可行:
@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屋!