Search in sources :

Example 1 with PageResultHandler

use of cn.hutool.db.handler.PageResultHandler in project hutool by looly.

the class SqlConnRunner method page.

/**
 * 分页查询<br>
 * 此方法不会关闭Connection
 *
 * @param conn 数据库连接对象
 * @param fields 返回的字段列表,null则返回所有字段
 * @param where 条件实体类(包含表名)
 * @param page 页码
 * @param numPerPage 每页条目数
 * @return 结果对象
 * @throws SQLException SQL执行异常
 */
public PageResult<Entity> page(Connection conn, Collection<String> fields, Entity where, int page, int numPerPage) throws SQLException {
    checkConn(conn);
    final int count = count(conn, where);
    PageResultHandler pageResultHandler = PageResultHandler.create(new PageResult<Entity>(page, numPerPage, count));
    return this.page(conn, fields, where, page, numPerPage, pageResultHandler);
}
Also used : PageResultHandler(cn.hutool.db.handler.PageResultHandler)

Example 2 with PageResultHandler

use of cn.hutool.db.handler.PageResultHandler in project hutool by looly.

the class SqlConnRunner method page.

/**
 * 分页查询<br>
 * 此方法不会关闭Connection
 *
 * @param conn 数据库连接对象
 * @param fields 返回的字段列表,null则返回所有字段
 * @param where 条件实体类(包含表名)
 * @param page 分页对象
 * @return 结果对象
 * @throws SQLException SQL执行异常
 */
public PageResult<Entity> page(Connection conn, Collection<String> fields, Entity where, Page page) throws SQLException {
    checkConn(conn);
    // 查询全部
    if (null == page) {
        List<Entity> entityList = this.find(conn, fields, where, new EntityListHandler());
        final PageResult<Entity> pageResult = new PageResult<Entity>(0, entityList.size(), entityList.size());
        pageResult.addAll(entityList);
        return pageResult;
    }
    final int count = count(conn, where);
    PageResultHandler pageResultHandler = PageResultHandler.create(new PageResult<Entity>(page.getPageNumber(), page.getPageSize(), count));
    return this.page(conn, fields, where, page, pageResultHandler);
}
Also used : EntityListHandler(cn.hutool.db.handler.EntityListHandler) PageResultHandler(cn.hutool.db.handler.PageResultHandler)

Aggregations

PageResultHandler (cn.hutool.db.handler.PageResultHandler)2 EntityListHandler (cn.hutool.db.handler.EntityListHandler)1