Spring mvc @RequestMapping不接受标头中的多个值

Spring mvc @RequestMapping不接受标头中的多个值,spring-mvc,Spring Mvc,我在请求头中添加了一个自定义参数。为什么@RequestMapping的标头中不可能有多个值: @RequestMapping(value="/mapping/header", method=RequestMethod.GET, headers={"version=1.0.1","version=1.0.2"}) public @ResponseBody String byHeaderValue(); 我也尝试了下面的代码,但不可能不起作用: @RequestMapping(value="/

我在请求头中添加了一个自定义参数。为什么@RequestMapping的标头中不可能有多个值:

@RequestMapping(value="/mapping/header", method=RequestMethod.GET, headers={"version=1.0.1","version=1.0.2"})
public @ResponseBody String byHeaderValue();
我也尝试了下面的代码,但不可能不起作用:

 @RequestMapping(value="/mapping/header", method=RequestMethod.GET, headers={"version=1.0.1,1.0.2"})
public @ResponseBody String byHeaderValue();
但如果我用两种不同的方法,它是有效的:

@RequestMapping(value="/mapping/header", method=RequestMethod.GET, headers="version=1.0.1")
public @ResponseBody String byHeaderValue1();

@RequestMapping(value="/mapping/header", method=RequestMethod.GET, headers="version=1.0.2")
public @ResponseBody String byHeaderValue2();

因为您试图指定两个同名的标题。标题名称必须是唯一的。

我尝试了标题={v1.0.1=1.0.1,v1.0.2=1.0.2},但它也不起作用。所以问题不是因为参数的名称相同。谢谢您的回复。为了消除使用的任何疑问,我尝试了:headers={version1=1,version2=2}。不可能,它不起作用。我添加了一个替代解决方案来解决您遇到的问题。这应该行得通。感谢您的努力,但我尝试使用此标头参数从服务器端选择正确的方法。所以我不需要客户端的版本,也不需要用响应对象将版本发送给客户端。标题中的版本参数是由客户端发送的。请参阅,很抱歉造成混淆。您是否尝试过用@RequestHeader注释2个字符串方法参数?