如何在iBatis中获得排序结果? [英] How to get a sorted result in iBatis?

查看:213
本文介绍了如何在iBatis中获得排序结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表的mgr_employee与2列managerName,teamEmployee。虽然我在SQL中进行排序,我得到未排序的java中的resultMap。
如何获得排序的映射?为什么iBatis混合了resultMap?

I have a table mgr_employee with 2 columns managerName, teamEmployee.
Although I do a sort in sql I get unsorted resultMap in java.
How can I get a sorted map? Why does iBatis mix up the resultMap?

<resultMap id="s_filter_defaults_ResultMap" class="java.util.HashMap">
  <result property="key" column="managerName"/>
  <result property="value" column="count"/>
</resultMap>

<select id="mCount" parameterClass="java.util.HashMap" resultMap="mcount_ResultMap">
    <![CDATA[
     select managerName, count(teamEmployee) AS count
      from mgr_employee
      group by managerName 
      order by managerName;
    ]]>
</select>

Java代码调用上面的sql:

Java code to call the above sql:

Map<String,Long> mCountMap = getSqlMapClientTemplate().queryForMap("mCount", "", "key", "value");

由于sql中的order by子句,mCountMap未按预期排序。
任何意见/建议,如何获得resultMap排序?

mCountMap is not sorted as was expected due to the "order by" clause in the sql. Any comments/suggestion, how to get the resultMap sorted?

推荐答案

我认为你的问题可能与Java使用的类型。需要查询列表,而不是Map,因为Java HashMap(我猜这是查询返回的内容)不支持排序。
请参阅 SqlMapDaoTemplate# queryForList()方法应该返回你需要的。

I think your problem might be with the Java types used. To need to query for a list, not for a Map, because the Java HashMap (I suppose this is what the query will return) doesn't have support for sorting. See the SqlMapDaoTemplate#queryForList() methods that should return what you need.

这篇关于如何在iBatis中获得排序结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆