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);
精彩评论