开发者

How can we use mysql's limits with iBatis generally?

I use iBatis 2.3.4

I have the following query:

<select id="getUserList" resultMap="userListResult">
    SELECT
            id,
            name,
            login,
            email
    FROM
          users
</select>

And when I need to provide paging I use:

sqlMap.queryForList("base.getUserList", startPosition, numItems);

Then iBatis generates query without limit, and skips extra data during fetchin开发者_如何学Cg. I belive that work with limits is more faster.

How can we push iBatis to use LIMIT generally? Is It possible? May be we can describe some dialect?


What's wrong with passing the limit,offset as parameters ? For example (in Postgresql, I think Mysql is similar) :

<select id="getUserList" resultMap="userListResult">
    SELECT  ...
    FROM  users
    LIMIT #limit:INTEGER# OFFSET #offset:INTEGER#
</select>

Then in your dao you could code:

  Map params = new HashMap();
  params.put("limit",10);
  params.put("offset",100);
  res = sqlMap.queryForList("base.getUserList", params);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜