这将起作用:
@RequestMapping(value = "/test", method = RequestMethod.POST,
headers = {"content-type=application/json"}) {
.......
}
如果我像下面这样添加另一个值,则它将失败并告诉我:
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认为两个内容类型值具有“AND”关系,但我希望它们是“OR”。
有什么建议?
谢谢!
最佳答案
您是否尝试过content-type=application/json,application/xml
?
不确定是否可以使用,但是在其中放置了两个content-type
header ,我认为只有一个会赢。
或
可以在具有不同RequestMapping
header 的同一方法上使用两个content-type
批注?
关于spring-mvc - Spring MVC @RequestMapping header 只能接受一个值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4962023/