Rajesh Bhat
Rajesh Bhat

Reputation: 811

How to pass string array to a @PathVariable in Java springs

I have below API to be tested. Not getting solution to pass string array to requestors. Tried with comma seperated values, values with in [] etc.

@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)

Upvotes: 0

Views: 1647

Answers (1)

Ye Win
Ye Win

Reputation: 2098

I'm not sure with @PathVariable but you can use the @RequestParam.

eg:

@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)

Upvotes: 1

Related Questions