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"}) {
.......
}
我猜这是因为 Spring 认为这两个 content type 值具有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
吗?
不确定它是否会起作用,但在其中放置两个 content-type
标头我认为只有一个会赢.
Not sure if it would work but putting two content-type
headers in there I think only one will win.
或
可能在具有不同 content-type
标头的同一方法上使用两个 RequestMapping
注释?
possibily use two RequestMapping
annotations on the same method with different content-type
headers?
这篇关于Spring MVC @RequestMapping 标头只能接受一个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!