I am trying to construct a url UriComponentsBuilder.
UriComponentsBuilder.fromUriString(BASE)
.pathSegment("api")
.pathSegment("v1")
.queryParam("param1", userId) //userId in null
.queryParam("param2",productId) //productId 12345
.build().toUriString();
What I got is like below as expected.
"http://localhost/api/v1?param1=¶m2=12345"
When one of these query params is null, I do not want that parameter key be part of url at all. So how can I dynamically construct URL when a parameter is null. I expect something like this:
"http://localhost/api/v1?param2=12345"