如何使用iBatis的限制?

时间:2021-11-01 00:54:06

I use iBatis 2.3.4

我使用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 fetching. I belive that work with limits is more faster.

然后iBatis无限制地生成查询,并在获取过程中跳过额外的数据。我相信有限度的工作会更快。

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

如何才能促使iBatis普遍使用极限?是可能的吗?我们可以描述一些方言吗?

1 个解决方案

#1


3  

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

通过极限值,作为参数的偏移量有什么问题?例如(在Postgresql中,我认为Mysql类似):

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

Then in your dao you could code:

那么在你的dao中你可以编码:

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

#1


3  

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

通过极限值,作为参数的偏移量有什么问题?例如(在Postgresql中,我认为Mysql类似):

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

Then in your dao you could code:

那么在你的dao中你可以编码:

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