Issue
How to pass multiple values in RequestParam and retrieve them.
public List<String> get(@RequestParam("query") String query)
query = [a | b | c].
Where a, b, and c are optional.
How can we pass the query as a param. When a&c are optional and if we pass ",b,".
Then I am getting array as[" ", b] after splitting with ",". Instead of [" ", b, " "].
How can I pass the query as a param, so that I can get an array of three strings?
Solution
You need distinct List params, each one named after the query param.
given i.e
request: /your-resource?param1=1,2,3¶m2=4,5¶m3=10
@Controller
@RequestMapping
public ResponseEntity<Object> foo(@RequestParam("params1") List<String> param1, @RequestParam("param2") List<String> params2, @RequestParam("param3") List<String> params3 )
Would result in 1,2,3 injected into param1. 4,5 into param2 and 10 into param3.
Answered By - Daniel Vilas-Boas