diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Brackets.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Brackets.java index a287ff71..459b5220 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Brackets.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/Brackets.java @@ -54,6 +54,10 @@ public class Brackets extends QueryCondition { return checkEffective() ? WrapperUtil.getValues(childCondition) : null; } + public QueryCondition getChildCondition(){ + return childCondition; + } + @Override public String toSql(List queryTables, IDialect dialect) { StringBuilder sql = new StringBuilder(); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WrapperUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WrapperUtil.java index 16906b1b..41e16a14 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WrapperUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WrapperUtil.java @@ -38,22 +38,34 @@ class WrapperUtil { List list = null; while (condition != null) { if (condition.checkEffective()) { - Object value = condition.getValue(); - if (value instanceof QueryWrapper) { - if (list == null) { - list = new ArrayList<>(); + if (condition instanceof Brackets) { + List childQueryWrapper = getChildSelect(((Brackets) condition).getChildCondition()); + if (!childQueryWrapper.isEmpty()) { + if (list == null) { + list = new ArrayList<>(); + } + list.addAll(childQueryWrapper); } - list.add((QueryWrapper) value); - list.addAll(((QueryWrapper) value).getChildSelect()); - } else if (value != null && value.getClass().isArray()) { - for (int i = 0; i < Array.getLength(value); i++) { - Object arrayValue = Array.get(value, i); - if (arrayValue instanceof QueryWrapper) { - if (list == null) { - list = new ArrayList<>(); + } + // not Brackets + else { + Object value = condition.getValue(); + if (value instanceof QueryWrapper) { + if (list == null) { + list = new ArrayList<>(); + } + list.add((QueryWrapper) value); + list.addAll(((QueryWrapper) value).getChildSelect()); + } else if (value != null && value.getClass().isArray()) { + for (int i = 0; i < Array.getLength(value); i++) { + Object arrayValue = Array.get(value, i); + if (arrayValue instanceof QueryWrapper) { + if (list == null) { + list = new ArrayList<>(); + } + list.add((QueryWrapper) arrayValue); + list.addAll(((QueryWrapper) arrayValue).getChildSelect()); } - list.add((QueryWrapper) arrayValue); - list.addAll(((QueryWrapper) arrayValue).getChildSelect()); } } } diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java index c4496c6c..4d7ffc54 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java @@ -64,6 +64,19 @@ public class EntityTestStarter { // Page paginate = accountMapper.paginate(1,10,queryWrapper); // System.out.println(paginate); + + +// QueryWrapper query = QueryWrapper.create() +// .where(ACCOUNT.ID.in( +// select(ACCOUNT.ID).from(ACCOUNT) +// .where(ACCOUNT.ID.eq(1)) +// ).and("1 = 1") +// ); +// +// List accounts = accountMapper.selectListByQuery(query); +// System.out.println(accounts); + + // List accounts = new ArrayList<>(); // for (int i = 0; i < 10; i++) { // Account account = new Account();