diff --git a/hutool-captcha/src/test/java/cn/hutool/captcha/CaptchaTest.java b/hutool-captcha/src/test/java/cn/hutool/captcha/CaptchaTest.java index 3d3a99190..6b9d1cb31 100644 --- a/hutool-captcha/src/test/java/cn/hutool/captcha/CaptchaTest.java +++ b/hutool-captcha/src/test/java/cn/hutool/captcha/CaptchaTest.java @@ -93,7 +93,6 @@ public class CaptchaTest { @Test @Ignore public void ShearCaptchaWithMathTest() { - // 定义图形验证码的长和宽 ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(200, 45, 4, 4); captcha.setGenerator(new MathGenerator()); diff --git a/hutool-db/src/main/java/cn/hutool/db/sql/SqlUtil.java b/hutool-db/src/main/java/cn/hutool/db/sql/SqlUtil.java index 65f49d7ec..471fc182c 100644 --- a/hutool-db/src/main/java/cn/hutool/db/sql/SqlUtil.java +++ b/hutool-db/src/main/java/cn/hutool/db/sql/SqlUtil.java @@ -111,10 +111,10 @@ public class SqlUtil { StringBuilder likeValue = StrUtil.builder(withLikeKeyword ? "LIKE " : ""); switch (likeType) { case StartWith: - likeValue.append('%').append(value); + likeValue.append(value).append('%'); break; case EndWith: - likeValue.append(value).append('%'); + likeValue.append('%').append(value); break; case Contains: likeValue.append('%').append(value).append('%'); 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 fb5318c51..d31ddac1d 100644 --- a/hutool-db/src/test/java/cn/hutool/db/DbTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/DbTest.java @@ -1,15 +1,13 @@ package cn.hutool.db; -import java.sql.SQLException; -import java.util.List; - +import cn.hutool.db.sql.Condition; +import cn.hutool.log.StaticLog; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; -import cn.hutool.core.lang.func.VoidFunc1; -import cn.hutool.db.sql.Condition; -import cn.hutool.log.StaticLog; +import java.sql.SQLException; +import java.util.List; /** * Db对象单元测试 @@ -29,7 +27,22 @@ public class DbTest { List find = Db.use().find(Entity.create("user").set("age", 18)); Assert.assertEquals("王五", find.get(0).get("name")); } - + + @Test + public void findLikeTest() throws SQLException { + // 方式1 + List find = Db.use().find(Entity.create("user").set("name", "like 王%")); + Assert.assertEquals("王五", find.get(0).get("name")); + + // 方式2 + find = Db.use().findLike("user", "name", "王", Condition.LikeType.StartWith); + Assert.assertEquals("王五", find.get(0).get("name")); + + // 方式3 + find = Db.use().query("select * from user where name like ?", "王%"); + Assert.assertEquals("王五", find.get(0).get("name")); + } + @Test public void findByTest() throws SQLException { List find = Db.use().findBy("user", @@ -45,14 +58,10 @@ public class DbTest { @Test @Ignore public void txTest() throws SQLException { - Db.use().tx(new VoidFunc1() { - - @Override - public void call(Db db) throws SQLException { - 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"); - } + Db.use().tx(db -> { + 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"); }); } } diff --git a/hutool-db/src/test/java/cn/hutool/db/MySQLTest.java b/hutool-db/src/test/java/cn/hutool/db/MySQLTest.java index c65140c32..ab90ffb6f 100644 --- a/hutool-db/src/test/java/cn/hutool/db/MySQLTest.java +++ b/hutool-db/src/test/java/cn/hutool/db/MySQLTest.java @@ -1,12 +1,10 @@ package cn.hutool.db; -import java.sql.SQLException; - +import cn.hutool.core.lang.Console; import org.junit.Ignore; import org.junit.Test; -import cn.hutool.core.lang.Console; -import cn.hutool.core.lang.func.VoidFunc1; +import java.sql.SQLException; /** * MySQL操作单元测试