mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
添加Entity.addCondition方法(issue#IBCDL2@Gitee)
This commit is contained in:
parent
a5d5af1b8f
commit
272ea525a2
@ -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);
|
||||
|
@ -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<Entity> all = Db.of("mariadb_local").findAll(
|
||||
Entity.of("user").addCondition(
|
||||
new Condition("name", "REGEXP", "张.*")));
|
||||
Console.log(all);
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user