如何在Java spring中将字符串数组传递给@PathVariable

时间:2016-11-04 07:56:36

标签: java spring spring-restcontroller spring-rest

我有以下API进行测试。没有获得将字符串数组传递给请求者的解决方案。尝试使用逗号分隔值,[]等中的值

@RequestMapping(value = "/v10/{user}/alerts/alertguids/{requestors}", method = RequestMethod.GET)
    @ResponseBody
    @ResponseStatus(HttpStatus.OK)
    public String[] retrieveRunnableAlertGuidsByRequestors(@RequestParam(value = "productId") final String productId,
                                                           @PathVariable final String[] requestors)

1 个答案:

答案 0 :(得分:1)

我对@PathVariable不确定,但您可以使用@RequestParam。

例如:

@RequestMapping(value = "/v10/{user}/alerts/alertguids/{requestors}", method = RequestMethod.GET)
    @ResponseBody
    @ResponseStatus(HttpStatus.OK)
    public String[] retrieveRunnableAlertGuidsByRequestors(@RequestParam(value = "productId") final String productId,
                                                           @RequestParam(value = "param[]")  final String[] requestors)