fixed and close #I6X4U8

This commit is contained in:
开源海哥 2023-04-21 12:55:18 +08:00
parent 9265fa7755
commit 3af6c82c67
3 changed files with 43 additions and 14 deletions

View File

@ -54,6 +54,10 @@ public class Brackets extends QueryCondition {
return checkEffective() ? WrapperUtil.getValues(childCondition) : null; return checkEffective() ? WrapperUtil.getValues(childCondition) : null;
} }
public QueryCondition getChildCondition(){
return childCondition;
}
@Override @Override
public String toSql(List<QueryTable> queryTables, IDialect dialect) { public String toSql(List<QueryTable> queryTables, IDialect dialect) {
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();

View File

@ -38,6 +38,17 @@ class WrapperUtil {
List<QueryWrapper> list = null; List<QueryWrapper> list = null;
while (condition != null) { while (condition != null) {
if (condition.checkEffective()) { if (condition.checkEffective()) {
if (condition instanceof Brackets) {
List<QueryWrapper> childQueryWrapper = getChildSelect(((Brackets) condition).getChildCondition());
if (!childQueryWrapper.isEmpty()) {
if (list == null) {
list = new ArrayList<>();
}
list.addAll(childQueryWrapper);
}
}
// not Brackets
else {
Object value = condition.getValue(); Object value = condition.getValue();
if (value instanceof QueryWrapper) { if (value instanceof QueryWrapper) {
if (list == null) { if (list == null) {
@ -58,6 +69,7 @@ class WrapperUtil {
} }
} }
} }
}
condition = condition.next; condition = condition.next;
} }
return list == null ? Collections.emptyList() : list; return list == null ? Collections.emptyList() : list;

View File

@ -64,6 +64,19 @@ public class EntityTestStarter {
// Page<Account> paginate = accountMapper.paginate(1,10,queryWrapper); // Page<Account> paginate = accountMapper.paginate(1,10,queryWrapper);
// System.out.println(paginate); // 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<Account> accounts = accountMapper.selectListByQuery(query);
// System.out.println(accounts);
// List<Account> accounts = new ArrayList<>(); // List<Account> accounts = new ArrayList<>();
// for (int i = 0; i < 10; i++) { // for (int i = 0; i < 10; i++) {
// Account account = new Account(); // Account account = new Account();