From baf185af93272b160645ef8e2157c45ff92a5979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Wed, 18 Oct 2023 11:57:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20QueryWrapper=20?= =?UTF-8?q?=E7=9A=84=20Plus=20=E5=85=BC=E5=AE=B9=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatisflex/core/query/QueryWrapper.java | 22 ++++++++++++++++++- .../coretest/PlusCompatibleTest.java | 4 ++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java index b7caf77f..4f260851 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java @@ -59,6 +59,27 @@ public class QueryWrapper extends BaseQueryWrapper { return tableInfo.buildQueryWrapper(entity, operators); } + /** + * 根据 Map 对象,构建查询条件 + * + * @param map Map 对象 + * @return 查询对象 QueryWrapper + */ + public static QueryWrapper create(Map map) { + return create().where(map); + } + + /** + * 根据 Map 构建查询条件 + * + * @param map Map 对象 + * @param operators 每个属性对应的操作符 + * @return 查询对象 QueryWrapper + */ + public static QueryWrapper create(Map map, SqlOperators operators) { + return create().where(map, operators); + } + @SuppressWarnings("unchecked") public WithBuilder with(String name) { @@ -1331,7 +1352,6 @@ public class QueryWrapper extends BaseQueryWrapper { } - /** * {@code IN(value)} * diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/PlusCompatibleTest.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/PlusCompatibleTest.java index c53ad5e5..1db77f88 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/PlusCompatibleTest.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/PlusCompatibleTest.java @@ -35,7 +35,7 @@ public class PlusCompatibleTest { .eq("column1", value1, If::hasText) .ge(Account::getAge, 18) .or(qw -> { - qw.like("column2", "value2"); + qw.likeLeft("column2", "value2"); }) .or(q1 -> { q1.eq("column3", "value3") @@ -44,7 +44,7 @@ public class PlusCompatibleTest { Assert.assertEquals("SELECT * FROM `user` " + "WHERE `tb_account`.`age` >= 18 " + - "OR (column2 LIKE '%value2%') " + + "OR (column2 LIKE 'value2%') " + "OR (column3 = 'value3' AND `tb_account`.`sex` >= 0)" , queryWrapper.toSQL());