mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
fixed:在某些场景下,动态条件时,生成的SQL错误。 close #I6W89G
This commit is contained in:
parent
09a6789482
commit
3108d8075f
@ -16,6 +16,7 @@
|
||||
package com.mybatisflex.core.query;
|
||||
|
||||
import com.mybatisflex.core.dialect.IDialect;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -58,11 +59,17 @@ public class Brackets extends QueryCondition {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
if (checkEffective()) {
|
||||
String childSql = childCondition.toSql(queryTables, dialect);
|
||||
QueryCondition effectiveBefore = getEffectiveBefore();
|
||||
if (effectiveBefore != null) {
|
||||
childSql = effectiveBefore.connector + "(" + childSql + ")";
|
||||
if (StringUtil.isNotBlank(childSql)) {
|
||||
QueryCondition effectiveBefore = getEffectiveBefore();
|
||||
if (effectiveBefore != null) {
|
||||
childSql = effectiveBefore.connector + "(" + childSql + ")";
|
||||
}
|
||||
sql.append(childSql);
|
||||
} else {
|
||||
//all child conditions is not effective
|
||||
//fixed gitee #I6W89G
|
||||
this.effective = false;
|
||||
}
|
||||
sql.append(childSql);
|
||||
}
|
||||
|
||||
if (this.next != null) {
|
||||
|
||||
@ -33,6 +33,9 @@ public class Account extends BaseAccount implements Serializable {
|
||||
|
||||
private TypeEnum typeEnum;
|
||||
|
||||
// @Column(isLogicDelete = true)
|
||||
// private boolean deleteFlag;
|
||||
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
@ -81,6 +84,30 @@ public class Account extends BaseAccount implements Serializable {
|
||||
options.put(key, value);
|
||||
}
|
||||
|
||||
public String getDeptId() {
|
||||
return deptId;
|
||||
}
|
||||
|
||||
public void setDeptId(String deptId) {
|
||||
this.deptId = deptId;
|
||||
}
|
||||
|
||||
public TypeEnum getTypeEnum() {
|
||||
return typeEnum;
|
||||
}
|
||||
|
||||
public void setTypeEnum(TypeEnum typeEnum) {
|
||||
this.typeEnum = typeEnum;
|
||||
}
|
||||
|
||||
// public boolean isDeleteFlag() {
|
||||
// return deleteFlag;
|
||||
// }
|
||||
//
|
||||
// public void setDeleteFlag(boolean deleteFlag) {
|
||||
// this.deleteFlag = deleteFlag;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Account{" +
|
||||
|
||||
@ -16,14 +16,18 @@
|
||||
package com.mybatisflex.test;
|
||||
|
||||
import com.mybatisflex.core.MybatisFlexBootstrap;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import org.apache.ibatis.logging.stdout.StdOutImpl;
|
||||
import com.mybatisflex.core.audit.AuditManager;
|
||||
import com.mybatisflex.core.audit.ConsoleMessageCollector;
|
||||
import com.mybatisflex.core.audit.MessageCollector;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mybatisflex.core.query.QueryMethods.select;
|
||||
import static com.mybatisflex.test.table.Tables.ACCOUNT;
|
||||
|
||||
public class EntityTestStarter {
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -35,10 +39,15 @@ public class EntityTestStarter {
|
||||
|
||||
MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance()
|
||||
.setDataSource(dataSource)
|
||||
.setLogImpl(StdOutImpl.class)
|
||||
.addMapper(AccountMapper.class)
|
||||
.start();
|
||||
|
||||
//开启审计功能
|
||||
AuditManager.setAuditEnable(true);
|
||||
|
||||
//设置 SQL 审计收集器
|
||||
MessageCollector collector = new ConsoleMessageCollector();
|
||||
AuditManager.setMessageCollector(collector);
|
||||
|
||||
// //查询 ID 为 1 的数据
|
||||
// Account account = bootstrap.execute(AccountMapper.class, accountMapper ->
|
||||
@ -46,14 +55,29 @@ public class EntityTestStarter {
|
||||
// System.out.println(account);
|
||||
|
||||
AccountMapper accountMapper = bootstrap.getMapper(AccountMapper.class);
|
||||
Account account = accountMapper.selectOneById(1);
|
||||
// Account account = accountMapper.selectOneById(1);
|
||||
|
||||
|
||||
List<Account> accounts = accountMapper.selectAll();
|
||||
|
||||
// QueryWrapper query = QueryWrapper.create().where(SYS_CONFIG.TYPE.eq(type).when(StrChecker.isNotBlank(type)))
|
||||
// .and(SYS_CONFIG.NAME.like(word).when(StrChecker.isNotBlank(word))
|
||||
// .or(SYS_CONFIG.CODE.like(word).when(StrChecker.isNotBlank(word)))
|
||||
// .or(SYS_CONFIG.VALUE.like(word).when(StrChecker.isNotBlank(word)))
|
||||
// .or(SYS_CONFIG.TYPE.like(word).when(StrChecker.isNotBlank(word)))
|
||||
// );
|
||||
|
||||
List<Account> accounts = accountMapper.selectListByQuery(
|
||||
select().where(ACCOUNT.AGE.ge(18).when(false))
|
||||
.and(ACCOUNT.USER_NAME.like("aaaa").when(false)
|
||||
.or(ACCOUNT.USER_NAME.like("aaaa").when(false))
|
||||
.or(ACCOUNT.USER_NAME.like("aaaa").when(false))
|
||||
.or(ACCOUNT.USER_NAME.like("aaaa").when(false))
|
||||
)
|
||||
);
|
||||
System.out.println(accounts);
|
||||
//
|
||||
long l = accountMapper.selectCountByQuery(QueryWrapper.create());
|
||||
System.out.println("count: "+ l);
|
||||
// long l = accountMapper.selectCountByQuery(QueryWrapper.create());
|
||||
// System.out.println("count: "+ l);
|
||||
|
||||
// System.out.println(account);
|
||||
//
|
||||
|
||||
@ -18,4 +18,20 @@ public enum TypeEnum {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user