Spring MVC - REST Get Method with RequestParam List <string> </string>

时间:2012-03-14 20:48:49

标签: rest spring-mvc

如果我有这样的控制器界面:

@RequestMapping(method = RequestMethod.GET, value = "/{CustomerId}/audit")
public @ResponseBody Long countAudit(
   @PathVariable(value = "CustomerId") String customerId,
   @RequestParam(value = "Users", required = false) List<String> users)

我使用RestTemplate通过getForObject进行调用,如下所示:

RestTemplate restTemplate = new RestTemplate();
List<String> users = new ArrayList<String>();
users.add("Bill");
users.add("John");
String customerId = "1234";
Long cnt = restTemplate.getForObject(url, Long.class, customerId, users);

为什么控制器端列表中的第一项有[前面,而最后一项有匹配]?

在客户端..它看起来像这样:“比尔”,“约翰” 在控制器(服务器)上,它看起来像这样:“[Bill”,“John]”

任何想法,有没有办法绕过这个或处理这个?关于如何传递List&lt;&gt;的任何其他建议通过resttemplate中的requestParam?谢谢你的任何建议..

1 个答案:

答案 0 :(得分:0)

服务器端解析json格式不正确。服务器不是解析它,而是为您提供完整消息的json字符串(["Bill", "John"])。

我无法告诉你为什么服务器没有正确解析它,但我希望提示可以帮助你找到问题。