开发者

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

开发者 https://www.devze.com 2023-01-07 11:25 出处:网络
I use iBatis 2.3.4 I have the following query: <select id=\"getUserList\" resultMap=\"userListResult\">

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

精彩评论

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