title: How to wrap multiple select queries into one query in Mybatis?
body: <p>How do I return multiple select queries in MyBatis? for example, I want to return a list of 20 users, the total number of users, say 1000. In the following example, I use SQL_CALC_FOUND_ROWS to get the total number before LIMIT applies, and use FOUND_ROWS() to retrieve the cached value in the second select query.</p>
  
  <pre><code>&lt;resultMap type="User" id="userResultMap"&gt;
      &lt;id property="id" column="u_id" /&gt;
      &lt;result property="username" column="u_username" /&gt;
          &lt;result property="password" column="u_password" /&gt;
          &lt;result property="email" column="u_email" /&gt;
  &lt;/resultMap&gt;
  
  &lt;select id="get" parameterType="Integer" resultType="list" resultMap="userResultMap"&gt;
          SELECT            
              SQL_CALC_FOUND_ROWS
              u.id                           AS u_id,
              u.username               AS u_username,
              u.password               AS u_password,
              u.email                     AS u_email
         FROM user u WHERE u.id=#{id}
         &lt;if test="startIndex != null and perPage != null"&gt;
              LIMIT #{startIndex}, #{perPage}
         &lt;/if&gt;
  
         SELECT FOUND_ROWS(), #{startIndex}, #{perPage};
  &lt;/select&gt;
  </code></pre>
  
  <p>I was thinking of adding another resultMap and didn't find a way to take multiple returns in Java Spring side.</p>
  
  <p>In the Java side, it was like</p>
  
  <pre><code>List&lt;User&gt; get(@Param("id") Integer id, @Param("startIndex") Integer startIndex,
              @Param("perPage") Integer perPage);
  </code></pre>