Skip to main content

Paging Queries

After linking a mapper interface to a mapper XML via @RefMapper, add a paging object argument to enable pagination.

Mapper Methods

Mapper methods with paging arguments
@RefMapper("/mapper/userMapper.xml")
public interface UserMapper {
List<User> listUsers1(@Param("searchId") long searchId, Page page);

PageResult<User> listUsers2(@Param("searchId") long searchId, Page page);
}

Return a List

Paging: return a list
Page pageInfo = PageObject.of(0, 20); // page 0, size 20 (0-based)
//or pageInfo = PageObject.of(1, 20, 1);// page 1, size 20 (1-based)

UserMapper userMapper = ...
List<User> result = userMapper.listUsers1(123, pageInfo);

Return a PageResult

Paging: return a PageResult
Page pageInfo = PageObject.of(0, 20); // page 0, size 20 (0-based)
//or pageInfo = PageObject.of(1, 20, 1);// page 1, size 20 (1-based)

UserMapper userMapper = ...
PageResult<User> result = userMapper.listUsers2(123, pageInfo);

Page Result Fields

  • PageResult also contains the original paging info, total rows, and total pages.