Search in sources :

Example 1 with EntityListHandler

use of cn.hutool.db.handler.EntityListHandler 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)

Example 2 with EntityListHandler

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

the class CRUDTest method findTest.

@Test
public void findTest() throws SQLException {
    List<Entity> find = runner.find(CollUtil.newArrayList("name AS name2"), Entity.create("user"), new EntityListHandler());
    Assert.assertFalse(find.isEmpty());
}
Also used : ActiveEntity(cn.hutool.db.ActiveEntity) Entity(cn.hutool.db.Entity) EntityListHandler(cn.hutool.db.handler.EntityListHandler) Test(org.junit.Test)

Example 3 with EntityListHandler

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

the class CRUDTest method findTest.

@Test
public void findTest() throws SQLException {
    List<Entity> find = db.find(CollUtil.newArrayList("name AS name2"), Entity.create("user"), new EntityListHandler());
    Assert.assertFalse(find.isEmpty());
}
Also used : EntityListHandler(cn.hutool.db.handler.EntityListHandler) Test(org.junit.Test)

Aggregations

EntityListHandler (cn.hutool.db.handler.EntityListHandler)3 Test (org.junit.Test)2 ActiveEntity (cn.hutool.db.ActiveEntity)1 Entity (cn.hutool.db.Entity)1 PageResultHandler (cn.hutool.db.handler.PageResultHandler)1