If you use Mappers (much easier than using raw SqlSessions), the easiest way to apply the restriction is to add the RowBounds parameter to the argument list of the mapping function, for example:
// without limit List<Foo> selectFooByExample(FooExample ex); // with limit List<Foo> selectFooByExample(FooExample ex, RowBounds rb);
This is referred to almost as an afterthought in a link posted in Vladimir under the heading “Using Mappers” and may use another accent:
You can also pass an instance of RowBounds to a method to limit query results.
Please note that support for RowBounds may vary by database. Mybatis documentation implies that Mybatis will make sure to use the appropriate query. However, for Oracle, at least this is handled by very inefficient database callbacks.
source share