From a3d5385efc7121223f0974f12b9d69a7f0ec9bf3 Mon Sep 17 00:00:00 2001 From: Looly Date: Sat, 30 Apr 2022 22:56:23 +0800 Subject: [PATCH] fix code --- .../main/java/cn/hutool/db/AbstractDb.java | 15 --------- .../src/test/java/cn/hutool/db/DbTest.java | 32 +++++++++---------- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/hutool-db/src/main/java/cn/hutool/db/AbstractDb.java b/hutool-db/src/main/java/cn/hutool/db/AbstractDb.java index c850d99a1..e610eabe7 100755 --- a/hutool-db/src/main/java/cn/hutool/db/AbstractDb.java +++ b/hutool-db/src/main/java/cn/hutool/db/AbstractDb.java @@ -867,21 +867,6 @@ public abstract class AbstractDb> implements ConnectionH } } - /** - * 分页查询
- * 查询条件为多个key value对表示,默认key = value,如果使用其它条件可以使用:where.put("key", " > 1"),value也可以传Condition对象,key被忽略 - * - * @param where 条件实体类(包含表名) - * @param page 页码 - * @param numPerPage 每页条目数 - * @return 分页结果集 - * @throws DbRuntimeException SQL执行异常 - * @since 3.2.2 - */ - public PageResult page(final Entity where, final int page, final int numPerPage) throws DbRuntimeException { - return this.page(where, new Page(page, numPerPage)); - } - /** * 分页查询
* 查询条件为多个key value对表示,默认key = value,如果使用其它条件可以使用:where.put("key", " > 1"),value也可以传Condition对象,key被忽略 diff --git a/hutool-db/src/test/java/cn/hutool/db/DbTest.java b/hutool-db/src/test/java/cn/hutool/db/DbTest.java index 9c55f7352..e0d26377c 100644 --- a/hutool-db/src/test/java/cn/hutool/db/DbTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/DbTest.java @@ -21,28 +21,28 @@ public class DbTest { @Test public void queryTest() { - final List find = Db.of().query("select * from ofr where age = ?", 18); + final List find = Db.of().query("select * from user where age = ?", 18); Assert.assertEquals("王五", find.get(0).get("name")); } @Test public void findTest() { - final List find = Db.of().find(Entity.create("ofr").set("age", 18)); + final List find = Db.of().find(Entity.create("user").set("age", 18)); Assert.assertEquals("王五", find.get(0).get("name")); } @Test public void pageTest() { // 测试数据库中一共4条数据,第0页有3条,第1页有1条 - final List page0 = Db.of().page(Entity.create("ofr"), 0, 3); + final List page0 = Db.of().page(Entity.create("user"), Page.of(0, 3)); Assert.assertEquals(3, page0.size()); - final List page1 = Db.of().page(Entity.create("ofr"), 1, 3); + final List page1 = Db.of().page(Entity.create("user"), Page.of(1, 3)); Assert.assertEquals(1, page1.size()); } @Test public void pageTest2() { - final String sql = "select * from ofr order by name"; + final String sql = "select * from user order by name"; // 测试数据库中一共4条数据,第0页有3条,第1页有1条 final List page0 = Db.of().page( sql, Page.of(0, 3)); @@ -55,7 +55,7 @@ public class DbTest { @Test public void pageWithParamsTest() { - final String sql = "select * from ofr where name = ?"; + final String sql = "select * from user where name = ?"; final PageResult result = Db.of().page( sql, Page.of(0, 3), "张三"); @@ -66,50 +66,50 @@ public class DbTest { @Test public void countTest() { - final long count = Db.of().count("select * from ofr"); + final long count = Db.of().count("select * from user"); Assert.assertEquals(4, count); } @Test public void countTest2() { - final long count = Db.of().count("select * from ofr order by name DESC"); + final long count = Db.of().count("select * from user order by name DESC"); Assert.assertEquals(4, count); } @Test public void findLikeTest() { // 方式1 - List find = Db.of().find(Entity.create("ofr").set("name", "like 王%")); + List find = Db.of().find(Entity.create("user").set("name", "like 王%")); Assert.assertEquals("王五", find.get(0).get("name")); // 方式2 - find = Db.of().findLike("ofr", "name", "王", Condition.LikeType.StartWith); + find = Db.of().findLike("user", "name", "王", Condition.LikeType.StartWith); Assert.assertEquals("王五", find.get(0).get("name")); // 方式3 - find = Db.of().query("select * from ofr where name like ?", "王%"); + find = Db.of().query("select * from user where name like ?", "王%"); Assert.assertEquals("王五", find.get(0).get("name")); } @Test public void findByTest() { - final List find = Db.of().findBy("ofr", + final List find = Db.of().findBy("user", Condition.parse("age", "> 18"), Condition.parse("age", "< 100") ); for (final Entity entity : find) { StaticLog.debug("{}", entity); } - Assert.assertEquals("unitTestofr", find.get(0).get("name")); + Assert.assertEquals("unitTestUser", find.get(0).get("name")); } @Test @Ignore public void txTest() throws SQLException { Db.of().tx(db -> { - db.insert(Entity.create("ofr").set("name", "unitTestofr2")); - db.update(Entity.create().set("age", 79), Entity.create("ofr").set("name", "unitTestofr2")); - db.del("ofr", "name", "unitTestofr2"); + db.insert(Entity.create("user").set("name", "unitTestuser2")); + db.update(Entity.create().set("age", 79), Entity.create("user").set("name", "unitTestuser2")); + db.del("user", "name", "unitTestuser2"); }); }