Spring MVC-带有RequestParam列表的REST Get方法<;字符串>;
如果我有这样的控制器接口:Spring MVC-带有RequestParam列表的REST Get方法<;字符串>;,rest,spring-mvc,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<Strin
@RequestMapping(method = RequestMethod.GET, value = "/{CustomerId}/audit")
public @ResponseBody Long countAudit(
@PathVariable(value = "CustomerId") String customerId,
@RequestParam(value = "Users", required = false) List<String> users)
@RequestMapping(method=RequestMethod.GET,value=“/{CustomerId}/audit”)
public@ResponseBody Long countAudit(
@PathVariable(value=“CustomerId”)字符串CustomerId,
@RequestParam(value=“Users”,required=false)列表用户)
我使用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);
RestTemplate RestTemplate=new RestTemplate();
列表用户=新建ArrayList();
用户。添加(“法案”);
用户。添加(“John”);
字符串customerId=“1234”;
Long cnt=restemplate.getForObject(url、Long.class、customerId、users);
为什么控制器端列表中的第一项前面有一个[而最后一项有匹配的]
以客户的名义。。看起来是这样的:“比尔”,“约翰”
在控制器(服务器)上,它如下所示:“[比尔”,“约翰]”
有什么想法吗?有没有办法解决这个问题?关于如何在resttemplate中通过requestParam传递列表,还有其他建议吗?感谢您的建议。服务器端解析json格式不正确。服务器不解析它,而是提供完整消息的json字符串(
[“Bill”,“John”]
)
我无法告诉您为什么服务器没有正确解析它,但我希望这个提示可以帮助您找到问题。服务器端解析json格式不正确。服务器不解析它,而是提供完整消息的json字符串(
[“Bill”,“John”]
)
我无法告诉您为什么服务器没有正确解析它,但我希望这个提示能帮助您找到问题。Hmm。。非常有趣。。这确实给了我一个线索。。因为我还没有使用JSON,所以我没有意识到这是JSON格式。非常感谢。嗯。。非常有趣。。这确实给了我一个线索。。因为我还没有使用JSON,所以我没有意识到这是JSON格式。非常感谢你。