mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-06 16:48:24 +08:00
feat: 新增 between 条件遇到 一个参数为 null 时自动转换成 LE 或 GE 逻辑 close #ICKPDB
This commit is contained in:
parent
cc2ca249e0
commit
b196fbb561
@ -513,18 +513,37 @@ public class QueryColumn implements CloneSupport<QueryColumn>, Conditional<Query
|
|||||||
if (values == null || values.length != 2) {
|
if (values == null || values.length != 2) {
|
||||||
throw new IllegalArgumentException("values is null or length is not 2");
|
throw new IllegalArgumentException("values is null or length is not 2");
|
||||||
}
|
}
|
||||||
return QueryColumnBehavior.castCondition(QueryCondition.create(this, SqlConsts.BETWEEN, values));
|
Object start = values[0], end = values[1];
|
||||||
|
return between_(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryCondition between_(Object start, Object end) {
|
QueryCondition between_(Object start, Object end) {
|
||||||
|
if (start == null && end == null) {
|
||||||
|
return QueryCondition.createEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean smartConvertBetweenToLeOrGe = QueryColumnBehavior.isSmartConvertBetweenToLeOrGe();
|
||||||
|
if ((start == null || end == null) && !smartConvertBetweenToLeOrGe) {
|
||||||
|
return QueryCondition.createEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* && end != null */
|
||||||
|
if (start == null) {
|
||||||
|
return le_(end);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* && start != null */
|
||||||
|
if (end == null) {
|
||||||
|
return ge_(start);
|
||||||
|
}
|
||||||
return QueryColumnBehavior.castCondition(QueryCondition.create(this, SqlConsts.BETWEEN, new Object[]{start, end}));
|
return QueryColumnBehavior.castCondition(QueryCondition.create(this, SqlConsts.BETWEEN, new Object[]{start, end}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryCondition between(Object[] values) {
|
public QueryCondition between(Object[] values) {
|
||||||
if (QueryColumnBehavior.shouldIgnoreValue(values)) {
|
// if (QueryColumnBehavior.shouldIgnoreValue(values)) {
|
||||||
return QueryCondition.createEmpty();
|
// return QueryCondition.createEmpty();
|
||||||
}
|
// }
|
||||||
return between_(values);
|
return between_(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,9 +557,9 @@ public class QueryColumn implements CloneSupport<QueryColumn>, Conditional<Query
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryCondition between(Object start, Object end) {
|
public QueryCondition between(Object start, Object end) {
|
||||||
if (QueryColumnBehavior.shouldIgnoreValue(start) || QueryColumnBehavior.shouldIgnoreValue(end)) {
|
// if (QueryColumnBehavior.shouldIgnoreValue(start) || QueryColumnBehavior.shouldIgnoreValue(end)) {
|
||||||
return QueryCondition.createEmpty();
|
// return QueryCondition.createEmpty();
|
||||||
}
|
// }
|
||||||
return between_(start, end);
|
return between_(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,9 +595,9 @@ public class QueryColumn implements CloneSupport<QueryColumn>, Conditional<Query
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryCondition notBetween(Object[] values) {
|
public QueryCondition notBetween(Object[] values) {
|
||||||
if (QueryColumnBehavior.shouldIgnoreValue(values)) {
|
// if (QueryColumnBehavior.shouldIgnoreValue(values)) {
|
||||||
return QueryCondition.createEmpty();
|
// return QueryCondition.createEmpty();
|
||||||
}
|
// }
|
||||||
return notBetween_(values);
|
return notBetween_(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -592,9 +611,9 @@ public class QueryColumn implements CloneSupport<QueryColumn>, Conditional<Query
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QueryCondition notBetween(Object start, Object end) {
|
public QueryCondition notBetween(Object start, Object end) {
|
||||||
if (QueryColumnBehavior.shouldIgnoreValue(start) || QueryColumnBehavior.shouldIgnoreValue(end)) {
|
// if (QueryColumnBehavior.shouldIgnoreValue(start) || QueryColumnBehavior.shouldIgnoreValue(end)) {
|
||||||
return QueryCondition.createEmpty();
|
// return QueryCondition.createEmpty();
|
||||||
}
|
// }
|
||||||
return notBetween_(start, end);
|
return notBetween_(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -94,7 +94,12 @@ public class QueryColumnBehavior {
|
|||||||
/**
|
/**
|
||||||
* 当 {@code IN(...)} 条件只有 1 个参数时,是否自动把的内容转换为相等。
|
* 当 {@code IN(...)} 条件只有 1 个参数时,是否自动把的内容转换为相等。
|
||||||
*/
|
*/
|
||||||
private static boolean smartConvertInToEquals = false;
|
private static boolean smartConvertInToEquals = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当 {@code BETWEEN ... AND ...} 条件只有 1 个参数时,是否自动把的内容转换为小于等于或大于等于。
|
||||||
|
*/
|
||||||
|
private static boolean smartConvertBetweenToLeOrGe = true;
|
||||||
|
|
||||||
public static Predicate<Object> getIgnoreFunction() {
|
public static Predicate<Object> getIgnoreFunction() {
|
||||||
return ignoreFunction;
|
return ignoreFunction;
|
||||||
@ -112,6 +117,14 @@ public class QueryColumnBehavior {
|
|||||||
QueryColumnBehavior.smartConvertInToEquals = smartConvertInToEquals;
|
QueryColumnBehavior.smartConvertInToEquals = smartConvertInToEquals;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isSmartConvertBetweenToLeOrGe() {
|
||||||
|
return smartConvertBetweenToLeOrGe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setSmartConvertBetweenToLeOrGe(boolean smartConvertBetweenToLeOrGe) {
|
||||||
|
QueryColumnBehavior.smartConvertBetweenToLeOrGe = smartConvertBetweenToLeOrGe;
|
||||||
|
}
|
||||||
|
|
||||||
static boolean shouldIgnoreValue(Object value) {
|
static boolean shouldIgnoreValue(Object value) {
|
||||||
return ignoreFunction.test(value);
|
return ignoreFunction.test(value);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user