From 272ea525a298150d479d81162792f0e8272dac69 Mon Sep 17 00:00:00 2001 From: Looly Date: Thu, 19 Dec 2024 21:25:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Entity.addCondition=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=88issue#IBCDL2@Gitee=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/dromara/hutool/db/Entity.java | 12 ++++++ .../hutool/db/sql/IssueIBCDL2Test.java | 37 +++++++++++++++++++ .../src/test/resources/config/db.setting | 6 +++ 3 files changed, 55 insertions(+) create mode 100644 hutool-db/src/test/java/org/dromara/hutool/db/sql/IssueIBCDL2Test.java diff --git a/hutool-db/src/main/java/org/dromara/hutool/db/Entity.java b/hutool-db/src/main/java/org/dromara/hutool/db/Entity.java index 17fa22d1d..c0b6e3b6d 100644 --- a/hutool-db/src/main/java/org/dromara/hutool/db/Entity.java +++ b/hutool-db/src/main/java/org/dromara/hutool/db/Entity.java @@ -26,6 +26,7 @@ import org.dromara.hutool.core.text.StrUtil; import org.dromara.hutool.core.array.ArrayUtil; import org.dromara.hutool.core.util.CharsetUtil; import org.dromara.hutool.core.util.ObjUtil; +import org.dromara.hutool.db.sql.Condition; import org.dromara.hutool.db.sql.SqlUtil; import java.nio.charset.Charset; @@ -318,6 +319,17 @@ public class Entity extends Dict { } // -------------------------------------------------------------------- Put and Set start + + /** + * 添加条件 + * + * @param condition 条件 + * @return this + */ + public Entity addCondition(final Condition condition) { + return set(condition.getField(), condition); + } + @Override public Entity set(final String field, final Object value) { return (Entity) super.set(field, value); diff --git a/hutool-db/src/test/java/org/dromara/hutool/db/sql/IssueIBCDL2Test.java b/hutool-db/src/test/java/org/dromara/hutool/db/sql/IssueIBCDL2Test.java new file mode 100644 index 000000000..e8bfaa6ac --- /dev/null +++ b/hutool-db/src/test/java/org/dromara/hutool/db/sql/IssueIBCDL2Test.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 Hutool Team and hutool.cn + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dromara.hutool.db.sql; + +import org.dromara.hutool.core.lang.Console; +import org.dromara.hutool.db.Db; +import org.dromara.hutool.db.Entity; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import java.util.List; + +public class IssueIBCDL2Test { + + @Test + @Disabled + void regexpTest(){ + final List all = Db.of("mariadb_local").findAll( + Entity.of("user").addCondition( + new Condition("name", "REGEXP", "张.*"))); + Console.log(all); + } +} diff --git a/hutool-db/src/test/resources/config/db.setting b/hutool-db/src/test/resources/config/db.setting index 7b5d44fb1..8c012da41 100644 --- a/hutool-db/src/test/resources/config/db.setting +++ b/hutool-db/src/test/resources/config/db.setting @@ -75,6 +75,12 @@ user = root pass = 123456 remarks = true +[mariadb_local] +url = jdbc:mysql://localhost:3306/test?useSSL=false +user = root +pass = 123456 +remarks = true + [postgre] url = jdbc:postgresql://looly.centos:5432/test_hutool user = postgres