This commit is contained in:
Looly 2019-11-22 07:29:07 +08:00
parent edb8b1ff8c
commit c4740a2c6b
4 changed files with 28 additions and 22 deletions

View File

@ -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());

View File

@ -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('%');

View File

@ -1,15 +1,13 @@
package cn.hutool.db; package cn.hutool.db;
import java.sql.SQLException; import cn.hutool.db.sql.Condition;
import java.util.List; 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 java.sql.SQLException;
import cn.hutool.db.sql.Condition; import java.util.List;
import cn.hutool.log.StaticLog;
/** /**
* Db对象单元测试 * Db对象单元测试
@ -30,6 +28,21 @@ public class DbTest {
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>() { Db.use().tx(db -> {
db.insert(Entity.create("user").set("name", "unitTestUser2"));
@Override db.update(Entity.create().set("age", 79), Entity.create("user").set("name", "unitTestUser2"));
public void call(Db db) throws SQLException { db.del("user", "name", "unitTestUser2");
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");
}
}); });
} }
} }

View File

@ -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 java.sql.SQLException;
import cn.hutool.core.lang.func.VoidFunc1;
/** /**
* MySQL操作单元测试 * MySQL操作单元测试