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;
|
package com.mybatisflex.core.query;
|
||||||
|
|
||||||
import com.mybatisflex.core.dialect.IDialect;
|
import com.mybatisflex.core.dialect.IDialect;
|
||||||
|
import com.mybatisflex.core.util.StringUtil;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -58,11 +59,17 @@ public class Brackets extends QueryCondition {
|
|||||||
StringBuilder sql = new StringBuilder();
|
StringBuilder sql = new StringBuilder();
|
||||||
if (checkEffective()) {
|
if (checkEffective()) {
|
||||||
String childSql = childCondition.toSql(queryTables, dialect);
|
String childSql = childCondition.toSql(queryTables, dialect);
|
||||||
QueryCondition effectiveBefore = getEffectiveBefore();
|
if (StringUtil.isNotBlank(childSql)) {
|
||||||
if (effectiveBefore != null) {
|
QueryCondition effectiveBefore = getEffectiveBefore();
|
||||||
childSql = effectiveBefore.connector + "(" + childSql + ")";
|
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) {
|
if (this.next != null) {
|
||||||
|
|||||||
@ -33,6 +33,9 @@ public class Account extends BaseAccount implements Serializable {
|
|||||||
|
|
||||||
private TypeEnum typeEnum;
|
private TypeEnum typeEnum;
|
||||||
|
|
||||||
|
// @Column(isLogicDelete = true)
|
||||||
|
// private boolean deleteFlag;
|
||||||
|
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
@ -81,6 +84,30 @@ public class Account extends BaseAccount implements Serializable {
|
|||||||
options.put(key, value);
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Account{" +
|
return "Account{" +
|
||||||
|
|||||||
@ -16,14 +16,18 @@
|
|||||||
package com.mybatisflex.test;
|
package com.mybatisflex.test;
|
||||||
|
|
||||||
import com.mybatisflex.core.MybatisFlexBootstrap;
|
import com.mybatisflex.core.MybatisFlexBootstrap;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.audit.AuditManager;
|
||||||
import org.apache.ibatis.logging.stdout.StdOutImpl;
|
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.EmbeddedDatabaseBuilder;
|
||||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.mybatisflex.core.query.QueryMethods.select;
|
||||||
|
import static com.mybatisflex.test.table.Tables.ACCOUNT;
|
||||||
|
|
||||||
public class EntityTestStarter {
|
public class EntityTestStarter {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -35,10 +39,15 @@ public class EntityTestStarter {
|
|||||||
|
|
||||||
MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance()
|
MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance()
|
||||||
.setDataSource(dataSource)
|
.setDataSource(dataSource)
|
||||||
.setLogImpl(StdOutImpl.class)
|
|
||||||
.addMapper(AccountMapper.class)
|
.addMapper(AccountMapper.class)
|
||||||
.start();
|
.start();
|
||||||
|
|
||||||
|
//开启审计功能
|
||||||
|
AuditManager.setAuditEnable(true);
|
||||||
|
|
||||||
|
//设置 SQL 审计收集器
|
||||||
|
MessageCollector collector = new ConsoleMessageCollector();
|
||||||
|
AuditManager.setMessageCollector(collector);
|
||||||
|
|
||||||
// //查询 ID 为 1 的数据
|
// //查询 ID 为 1 的数据
|
||||||
// Account account = bootstrap.execute(AccountMapper.class, accountMapper ->
|
// Account account = bootstrap.execute(AccountMapper.class, accountMapper ->
|
||||||
@ -46,14 +55,29 @@ public class EntityTestStarter {
|
|||||||
// System.out.println(account);
|
// System.out.println(account);
|
||||||
|
|
||||||
AccountMapper accountMapper = bootstrap.getMapper(AccountMapper.class);
|
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);
|
System.out.println(accounts);
|
||||||
//
|
//
|
||||||
long l = accountMapper.selectCountByQuery(QueryWrapper.create());
|
// long l = accountMapper.selectCountByQuery(QueryWrapper.create());
|
||||||
System.out.println("count: "+ l);
|
// System.out.println("count: "+ l);
|
||||||
|
|
||||||
// System.out.println(account);
|
// System.out.println(account);
|
||||||
//
|
//
|
||||||
|
|||||||
@ -18,4 +18,20 @@ public enum TypeEnum {
|
|||||||
this.code = code;
|
this.code = code;
|
||||||
this.desc = desc;
|
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