Search code examples
springweb-servicesresthttp-request-parameters

Get selective params as a map in Spring REST


I have written a Spring REST service which takes 4 parameters. One of the params "login" is known and the rest of the 3 are dynamic. is there any way in which I can get login as a param and rest of the params in a MultiValue Map ? I tried the following and got value in both the variable "login" and it was also included in the Multivalue Map. I want login to be not included in the MultiValue Map

public void getDataForDownload(@RequestParam("login") String login, @RequestParam MultiValueMap<String, Object> parameters, HttpServletResponse response) throws Exception
{
    response.setContentType("text/csv");
    String headerKey = "Content-Disposition";
    String headerValue = String.format("attachment; filename=\"%s\"",
            DOWNLOAD_FILE_NAME);
    response.setHeader(headerKey, headerValue);
    Map<String, Object> params = getParamsAsMap(parameters);
    m_download.writeDataToWriter(response.getWriter(), params);
    response.getWriter().close();
}

sample URL : localost:8080/download?login=xyz@xyx.com&param1=1&param2=2&param3=3

when I print the variables

login:xyz@xyx.com

map:

login = xyz@xyx.com
param1 = 1
param2 = 2
param3 = 3

Please let me know if what I am looking for can be done


Solution

  • This can't be done. Request param "name" will be always included in all params because it is a request parameter. You can remove it manually from params map.