mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
添加ifAbsent
This commit is contained in:
parent
a2756a9dde
commit
a2bdce7614
@ -73,7 +73,8 @@ public class MybatisPlusJoinAutoConfiguration {
|
|||||||
ConfigProperties.logicDelType = this.properties.getLogicDelType();
|
ConfigProperties.logicDelType = this.properties.getLogicDelType();
|
||||||
ConfigProperties.mappingMaxCount = this.properties.getMappingMaxCount();
|
ConfigProperties.mappingMaxCount = this.properties.getMappingMaxCount();
|
||||||
ConfigProperties.ifAbsent = Optional.ofNullable(ifAbsentConsumers.getIfAvailable())
|
ConfigProperties.ifAbsent = Optional.ofNullable(ifAbsentConsumers.getIfAvailable())
|
||||||
.map(m -> (BiPredicate<Object, IfAbsentSqlKeyWordEnum>) m).orElse(this.properties.getIfAbsent());
|
.map(m -> (BiPredicate<Object, IfAbsentSqlKeyWordEnum>) m)
|
||||||
|
.orElse((val, key) -> this.properties.getIfAbsent().test(val));
|
||||||
info("mybatis plus join properties config complete");
|
info("mybatis plus join properties config complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,5 +59,5 @@ public class ConfigProperties {
|
|||||||
* <p>
|
* <p>
|
||||||
* NOT_BLANK 非空白字符串 例: "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
|
* NOT_BLANK 非空白字符串 例: "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
|
||||||
*/
|
*/
|
||||||
public static BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent = IfAbsentEnum.NOT_EMPTY;
|
public static BiPredicate<Object, IfAbsentSqlKeyWordEnum> ifAbsent = (val, key) -> IfAbsentEnum.NOT_EMPTY.test(val);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package com.github.yulichang.config.enums;
|
package com.github.yulichang.config.enums;
|
||||||
|
|
||||||
import com.github.yulichang.toolkit.MPJStringUtils;
|
import com.github.yulichang.toolkit.MPJStringUtils;
|
||||||
import com.github.yulichang.wrapper.enums.IfAbsentSqlKeyWordEnum;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 条件判断策略
|
* 条件判断策略
|
||||||
@ -12,29 +11,29 @@ import java.util.function.BiPredicate;
|
|||||||
* @author yulichang
|
* @author yulichang
|
||||||
* @since 1.4.9
|
* @since 1.4.9
|
||||||
*/
|
*/
|
||||||
public enum IfAbsentEnum implements BiPredicate<Object, IfAbsentSqlKeyWordEnum> {
|
public enum IfAbsentEnum implements Predicate<Object> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 非null
|
* 非null
|
||||||
*/
|
*/
|
||||||
NOT_NULL((val, key) -> Objects.nonNull(val)),
|
NOT_NULL(Objects::nonNull),
|
||||||
/**
|
/**
|
||||||
* 非空字符串 例: "" -> false, " " -> true ...
|
* 非空字符串 例: "" -> false, " " -> true ...
|
||||||
*/
|
*/
|
||||||
NOT_EMPTY((val, key) -> NOT_NULL.test(val, key) && (!(val instanceof CharSequence) || MPJStringUtils.isNotEmpty((CharSequence) val))),
|
NOT_EMPTY(val -> NOT_NULL.and(v -> !(v instanceof CharSequence) || MPJStringUtils.isNotEmpty((CharSequence) v)).test(val)),
|
||||||
/**
|
/**
|
||||||
* NOT_BLANK 非空白字符串 例: "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
|
* NOT_BLANK 非空白字符串 例: "" -> false, " " -> false, "\r" -> false, "abc" -> true ...
|
||||||
*/
|
*/
|
||||||
NOT_BLANK((val, key) -> NOT_NULL.test(val, key) && (!(val instanceof CharSequence) || MPJStringUtils.isNotBlank((CharSequence) val)));
|
NOT_BLANK(val -> NOT_NULL.and(v -> !(v instanceof CharSequence) || MPJStringUtils.isNotBlank((CharSequence) v)).test(val));
|
||||||
|
|
||||||
private final BiPredicate<Object, IfAbsentSqlKeyWordEnum> predicate;
|
private final Predicate<Object> predicate;
|
||||||
|
|
||||||
IfAbsentEnum(BiPredicate<Object, IfAbsentSqlKeyWordEnum> predicate) {
|
IfAbsentEnum(Predicate<Object> predicate) {
|
||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(Object obj, IfAbsentSqlKeyWordEnum keyword) {
|
public boolean test(Object obj) {
|
||||||
return this.predicate.test(obj, keyword);
|
return this.predicate.test(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,17 +22,17 @@ public class IfAbsentTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void ifAbsent() {
|
void ifAbsent() {
|
||||||
assert IfAbsentEnum.NOT_EMPTY.test("\t", null);
|
assert IfAbsentEnum.NOT_EMPTY.test("\t");
|
||||||
assert !IfAbsentEnum.NOT_EMPTY.test("", null);
|
assert !IfAbsentEnum.NOT_EMPTY.test("");
|
||||||
assert IfAbsentEnum.NOT_EMPTY.test(" ", null);
|
assert IfAbsentEnum.NOT_EMPTY.test(" ");
|
||||||
assert IfAbsentEnum.NOT_EMPTY.test("\r", null);
|
assert IfAbsentEnum.NOT_EMPTY.test("\r");
|
||||||
assert IfAbsentEnum.NOT_EMPTY.test("a", null);
|
assert IfAbsentEnum.NOT_EMPTY.test("a");
|
||||||
|
|
||||||
assert !IfAbsentEnum.NOT_BLANK.test("\t", null);
|
assert !IfAbsentEnum.NOT_BLANK.test("\t");
|
||||||
assert !IfAbsentEnum.NOT_BLANK.test("", null);
|
assert !IfAbsentEnum.NOT_BLANK.test("");
|
||||||
assert !IfAbsentEnum.NOT_BLANK.test(" ", null);
|
assert !IfAbsentEnum.NOT_BLANK.test(" ");
|
||||||
assert !IfAbsentEnum.NOT_BLANK.test("\r", null);
|
assert !IfAbsentEnum.NOT_BLANK.test("\r");
|
||||||
assert IfAbsentEnum.NOT_BLANK.test("a", null);
|
assert IfAbsentEnum.NOT_BLANK.test("a");
|
||||||
|
|
||||||
ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_id, " +
|
ThreadLocalUtils.set("SELECT t.id, t.pid, t.`name`, t.`json`, t.sex, t.head_img, t.create_time, t.address_id, " +
|
||||||
"t.address_id2, t.del, t.create_by, t.update_by FROM `user` t " +
|
"t.address_id2, t.del, t.create_by, t.update_by FROM `user` t " +
|
||||||
|
Loading…
x
Reference in New Issue
Block a user