Debanjan Debanjan - 3 months ago 24
Java Question

Receive Collection/Iterable as arguments in spring boot controller

I am new to Spring and I want to write a controller which will take

Collection
/
Iterable
as arguments. Like this:

@RequestMapping(value = "friends", method = RequestMethod.POST)
public @ResponseBody Callable<Iterable<User>>
getFriendsOfUser(@RequestParam(required = true, name = "mobiles") Iterable<String> mobs) {
// return callable
}


There is no compilation error, but I cannot make it work. Can you say how will this work? And how shall be the request to this api be constructed?

Answer
public String getFriendsOfUser(@RequestParam(required = true, value = "mobiles")  String[] mobiless){
....
}

and your mobile should be

mobiles=myValue1&mobiles=myValue2&mobiles=myValue3

or

mobiles=myvalue1,myValue2,myValue3

still if you have any doubt post your front-end code and Ajax call.