title: return HashMap as the result in Mybatis
body: <p>I have a table department which has department_id as id column and employee name
  under employee column. I need to return a HashMap with departId as the key and number of employees
  of the department as the value. I wrote this code below in mybatis</p>
  
  <p>In Deptmapper.xml I have</p>
  
  <pre><code>&lt;select id="getAll” resultType="hashmap"&gt;
      SELECT id as dept_id,count(employee) as headCount
      FROM department
  &lt;/select&gt;
  </code></pre>
  
  <p>In Deptmapper.java I have</p>
  
  <pre><code>Void getAll(ResultHandler handler);
  </code></pre>
  
  <p>In DeptmapperDAO.java</p>
  
  <pre><code>public Map&lt;Integer,Integer&gt; getAll() {
  
      HashMapResultHandler resultHandler= new HashMapResultHandler();
      deptmapper. getAll(resultHandler);
      return resultHandler.getMap();
  }
  </code></pre>
  
  <p>In HashMapResultHandler.java I have</p>
  
  <pre><code>public class HashMapResultHandler implements ResultHandler{
  
      private Map&lt;Integer,Integer&gt; map = new HashMap&lt;Integer, Integer&gt;();
  
      @Override
      public void handleResult(ResultContext resultContext) {
  
          HashMap&lt;String,Object&gt; resultObject = (HashMap&lt;String,Object&gt;) resultContext.getResultObject();
          System.out.println("resultObject   ---&gt; "+resultObject.keySet());
           map.put(Integer.valueOf((String)resultObject.get("dept_id")),Integer.valueOf((String)resultObject.get(“head_count")));
  
      }
  
      public Map&lt;Integer,Integer&gt; getMap(){
          return map;
      }
  }
  </code></pre>
  
  <p>When I debug this code. I’m always getting <code>resultContext.getResultObject();</code>  as Null. Any idea what I’m missing? </p>