Looly 6 years ago
parent
commit
c4740a2c6b

+ 0 - 1
hutool-captcha/src/test/java/cn/hutool/captcha/CaptchaTest.java

@@ -93,7 +93,6 @@ public class CaptchaTest {
 	@Test
 	@Test
 	@Ignore
 	@Ignore
 	public void ShearCaptchaWithMathTest() {
 	public void ShearCaptchaWithMathTest() {
-		
 		// 定义图形验证码的长和宽
 		// 定义图形验证码的长和宽
 		ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(200, 45, 4, 4);
 		ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(200, 45, 4, 4);
 		captcha.setGenerator(new MathGenerator());
 		captcha.setGenerator(new MathGenerator());

+ 2 - 2
hutool-db/src/main/java/cn/hutool/db/sql/SqlUtil.java

@@ -111,10 +111,10 @@ public class SqlUtil {
 		StringBuilder likeValue = StrUtil.builder(withLikeKeyword ? "LIKE " : "");
 		StringBuilder likeValue = StrUtil.builder(withLikeKeyword ? "LIKE " : "");
 		switch (likeType) {
 		switch (likeType) {
 			case StartWith:
 			case StartWith:
-				likeValue.append('%').append(value);
+				likeValue.append(value).append('%');
 				break;
 				break;
 			case EndWith:
 			case EndWith:
-				likeValue.append(value).append('%');
+				likeValue.append('%').append(value);
 				break;
 				break;
 			case Contains:
 			case Contains:
 				likeValue.append('%').append(value).append('%');
 				likeValue.append('%').append(value).append('%');

+ 24 - 15
hutool-db/src/test/java/cn/hutool/db/DbTest.java

@@ -1,15 +1,13 @@
 package cn.hutool.db;
 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.Assert;
 import org.junit.Ignore;
 import org.junit.Ignore;
 import org.junit.Test;
 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对象单元测试
  * Db对象单元测试
@@ -29,7 +27,22 @@ public class DbTest {
 		List<Entity> find = Db.use().find(Entity.create("user").set("age", 18));
 		List<Entity> find = Db.use().find(Entity.create("user").set("age", 18));
 		Assert.assertEquals("王五", find.get(0).get("name"));
 		Assert.assertEquals("王五", find.get(0).get("name"));
 	}
 	}
-	
+
+	@Test
+	public void findLikeTest() throws SQLException {
+		// 方式1
+		List<Entity> 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
 	@Test
 	public void findByTest() throws SQLException {
 	public void findByTest() throws SQLException {
 		List<Entity> find = Db.use().findBy("user",
 		List<Entity> find = Db.use().findBy("user",
@@ -45,14 +58,10 @@ public class DbTest {
 	@Test
 	@Test
 	@Ignore
 	@Ignore
 	public void txTest() throws SQLException {
 	public void txTest() throws SQLException {
-		Db.use().tx(new VoidFunc1<Db>() {
-			
-			@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");
 		});
 		});
 	}
 	}
 }
 }

+ 2 - 4
hutool-db/src/test/java/cn/hutool/db/MySQLTest.java

@@ -1,12 +1,10 @@
 package cn.hutool.db;
 package cn.hutool.db;
 
 
-import java.sql.SQLException;
-
+import cn.hutool.core.lang.Console;
 import org.junit.Ignore;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.Test;
 
 
-import cn.hutool.core.lang.Console;
-import cn.hutool.core.lang.func.VoidFunc1;
+import java.sql.SQLException;
 
 
 /**
 /**
  * MySQL操作单元测试
  * MySQL操作单元测试