mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
4613d47c84
commit
514bb54ea5
@ -673,21 +673,10 @@ public abstract class AbstractDb<R extends AbstractDb<R>> implements ConnectionH
|
|||||||
* @throws DbRuntimeException SQL执行异常
|
* @throws DbRuntimeException SQL执行异常
|
||||||
*/
|
*/
|
||||||
public long count(final Entity where) throws DbRuntimeException {
|
public long count(final Entity where) throws DbRuntimeException {
|
||||||
return count(where, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 结果的条目数
|
|
||||||
*
|
|
||||||
* @param where 查询条件
|
|
||||||
* @return 复合条件的结果数
|
|
||||||
* @throws DbRuntimeException SQL执行异常
|
|
||||||
*/
|
|
||||||
public long count(final Entity where, final Page page) throws DbRuntimeException {
|
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
try {
|
try {
|
||||||
conn = this.getConnection();
|
conn = this.getConnection();
|
||||||
return runner.count(conn, Query.of(where).setPage(page));
|
return runner.count(conn, Query.of(where));
|
||||||
} finally {
|
} finally {
|
||||||
this.closeConnection(conn);
|
this.closeConnection(conn);
|
||||||
}
|
}
|
||||||
|
@ -316,7 +316,9 @@ public class DialectRunner implements Serializable {
|
|||||||
public PageResult<Entity> page(final Connection conn, final Query query) throws DbRuntimeException {
|
public PageResult<Entity> page(final Connection conn, final Query query) throws DbRuntimeException {
|
||||||
final Page page = query.getPage();
|
final Page page = query.getPage();
|
||||||
final PageResultHandler pageResultHandler = new PageResultHandler(
|
final PageResultHandler pageResultHandler = new PageResultHandler(
|
||||||
new PageResult<>(page.getPageNumber(), page.getPageSize(), (int) count(conn, query)),
|
new PageResult<>(page.getPageNumber(), page.getPageSize(),
|
||||||
|
// 分页查询中总数的查询要去掉分页信息
|
||||||
|
(int) count(conn, query.clone().setPage(null))),
|
||||||
this.caseInsensitive);
|
this.caseInsensitive);
|
||||||
return page(conn, query, pageResultHandler);
|
return page(conn, query, pageResultHandler);
|
||||||
}
|
}
|
||||||
|
@ -41,15 +41,6 @@ public class DbTest {
|
|||||||
Assert.assertEquals(1, page1.size());
|
Assert.assertEquals(1, page1.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void pageTest2() {
|
|
||||||
final long count = Db.of().count(Entity.create("user"), Page.of(1, 3));
|
|
||||||
Assert.assertEquals(1, count);
|
|
||||||
|
|
||||||
final List<Entity> page1 = Db.of().page(Entity.create("user"), Page.of(1, 3));
|
|
||||||
Assert.assertEquals(1, page1.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pageBySqlTest() {
|
public void pageBySqlTest() {
|
||||||
final String sql = "select * from user order by name";
|
final String sql = "select * from user order by name";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user