Is it possible to build a url with multiple parameter values as a comma separated list?
The following snippet prints a url:
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.UriComponentsBuilder;
public class MyMain {
public static void main(String[] args) {
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
queryParams.add("order", "1");
queryParams.add("order", "2");
System.out.println(UriComponentsBuilder.fromHttpUrl("http://example.com")
.queryParams(queryParams)
.build()
.toString());
}
}
The url produced by this code is:
http://example.com?order=1&order=2
What I would like to get is:
http://example.com?order=1,2
Using another framework is not an option and since I'm using a framework I would like to avoid building the logic to compose the url my way.
Is there anything in spring web or spring boot that can do this?