mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 09:08:24 +08:00
test: 测试动态添加 where 条件。
This commit is contained in:
parent
1f4dcff8b6
commit
96c96d21ef
@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
package com.mybatisflex.coretest;
|
package com.mybatisflex.coretest;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.query.CPI;
|
||||||
|
import com.mybatisflex.core.query.QueryTable;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
import com.mybatisflex.core.query.SqlConnector;
|
||||||
import com.mybatisflex.core.util.CollectionUtil;
|
import com.mybatisflex.core.util.CollectionUtil;
|
||||||
import com.mybatisflex.core.util.StringUtil;
|
import com.mybatisflex.core.util.StringUtil;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -79,4 +82,22 @@ public class DynamicConditionTest {
|
|||||||
System.out.println(sql);
|
System.out.println(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test05() {
|
||||||
|
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||||
|
.from(ACCOUNT)
|
||||||
|
.where(ACCOUNT.ID.in(1, 2, 3));
|
||||||
|
|
||||||
|
boolean anyMatch = CPI.getQueryTables(queryWrapper)
|
||||||
|
.stream()
|
||||||
|
.map(QueryTable::getName)
|
||||||
|
.anyMatch(tableName -> tableName.equals(ACCOUNT.getTableName()));
|
||||||
|
|
||||||
|
if (anyMatch) {
|
||||||
|
CPI.addWhereQueryCondition(queryWrapper, ACCOUNT.AGE.ge(18), SqlConnector.AND);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(queryWrapper.toSQL());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user