I have a parameter map and I am trying to build the complete url by appending the request parameters to the url.
Following code is what I have done so far to extract key values from the parameter map.
Map<String, String[]> parameters = request.getParameterMap();
String params = parameters.entrySet()
.stream()
.map(e -> e.getKey() + "=" + String.join(",", e.getValue()))
.collect(Collectors.joining("&"));
String url = requestUrl + "?" + params;
My url currently prints something similar to following if I pass value only to the year
parameter:
/student/query?Id=&grade=&year=2018
I want to print something like:
/student/query?year=2018
If I do not pass value for a certain parameter I do not want it to be printed.
How can I fix this?