title: Spring Boot Rest Web Service fetching multiple parameters in Get Request
body: <p>I am creating Spring Boot Web service and I have a Model Employee</p>
  
  <pre><code>public class Employee {
    private String id;
    private String name;
    private String designation;
    private int salary;
   //Has Getters and Setters
  }
  </code></pre>
  
  <p>I want to create a Get request which will fetching and filter the List of Employees based on the parameters given by user.</p>
  
  <p>For example, if the user gives name of an employee and designation of employee, the get method should filter those result. For various combination of parameters it should work.</p>
  
  <pre><code>@Override
      public List&lt;Employee&gt; getEmployees(Map&lt;String, Object&gt; parameters) {
          if (parameters.size() == 0)
  //          code to return all employees;
          List&lt;Employee&gt; selectedEmployees = new ArrayList&lt;Employee&gt;();
          for(Employee currentEmployee: new ArrayList&lt;Employee&gt;(employee.values())) {
              for(Map.Entry&lt;String, Object&gt; check: parameters.entrySet()) {
                  try {
                      if(check.getValue() instanceof Integer) {
                          int condition = (int) Employee.class.getMethod("get" + check.getKey()).invoke(currentEmployee);
                          if((int) check.getValue() == condition)
                              selectedEmployees.add(currentEmployee);
                      } else if (check.getValue() instanceof String) {
                          String condition = (String) Employee.class.getMethod("get" + check.getKey()).invoke(currentEmployee);
                          if (((String) check.getValue()).equals(condition))
                              selectedEmployees.add(currentEmployee);
                      }
                  } catch(Exception e){
                      e.printStackTrace();
                  }
              }
          }
          return selectedEmployees; 
      }
  </code></pre>
  
  <p>In order to avoid multiple if else cases I am filtering list based on String and Integer above.</p>
  
  <p>I think I am making an error in the below code which sending request in Controller.</p>
  
  <pre><code>@RequestMapping(value={"/employees","/{id}/{name}/{designation}/{salary}"})
      public List&lt;Employee&gt; getEmployeeByProperty(EmployeeRequestParameters requestParams){
          //Map for storing parameters to filter the List
          Map&lt;String, Object&gt; filterParams = new HashMap&lt;&gt;();
          if(requestParams.getIdParam().isEmpty()) {
              filterParams.put("id", Integer.parseInt(requestParams.getIdParam()));   
          } 
          if(!requestParams.getNameParam().isEmpty()) {
              filterParams.put("name", requestParams.getNameParam()); 
          } 
          if(!requestParams.getDesignationParam().isEmpty()) {
              filterParams.put("designation", requestParams.getDesignationParam());   
          } 
          if(requestParams.getSalaryParam().isEmpty()) {
              filterParams.put("salary", Integer.parseInt(requestParams.getSalaryParam()));   
          }       
          return EmployeeService.getEmployeesByProperty(filterParams);
      }
  </code></pre>