0

I want to pass array as path parameter in URL.

My code is as follows:

Controller:

@RequestMapping(value = "/getAllProcessInstancesByLocation/[{location_id}]" , method = RequestMethod.GET)
     public String getAllProcessInstances(@PathVariable("location_id") String[] location_id) {
         try {
        return processService.getAllProcessInstancesByLocation(location_id);
         }catch(Exception e) {
             return "error=>"+e.getMessage();
         }

     }

When I try to test this through browser I am getting following error:

http://localhost:8088/super-admin/getAllProcessInstancesByLocation/[%7B8,9%7D]

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Wed Jul 11 12:54:55 IST 2018 There was an unexpected error (type=Internal Server Error, status=500). Could not get HttpServletRequest URI: Illegal character in path at index 67: http://localhost:8088/super-admin/getAllProcessInstancesByLocation/[%7B8,9%7D]

How to pass the array in url? I want to pass as follows:

http://localhost:8088/super-admin/getAllProcessInstancesByLocation/[7,9,11]
James Z
  • 12,209
  • 10
  • 24
  • 44
user8030367
  • 81
  • 4
  • 18
  • Possible duplicate of [Passing an Array or List to @Pathvariable - Spring/Java](https://stackoverflow.com/questions/9623258/passing-an-array-or-list-to-pathvariable-spring-java) – Ryuzaki L Jul 11 '18 at 12:41

1 Answers1

0

It should be

@RequestMapping(value = "/getAllProcessInstancesByLocation/{location_id}" ...

not

@RequestMapping(value = "/getAllProcessInstancesByLocation/[{location_id}]" ...

So for example the following controller would return ["a","b","c","1","2","3"] when calling GET http://localhost:8080/getAllProcessInstancesByLocation/a,b,c,1,2,3:

@Controller
public class MyController {
    @RequestMapping("/getAllProcessInstancesByLocation/{locationId}")
    @ResponseBody
    public String[] getAllProcessInstances(@PathVariable String[] locationId){
        return locationId;
    }
}
AlexLiesenfeld
  • 2,872
  • 7
  • 36
  • 57