Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExampleWrapper condition 系列方法新增 Supplier 重载 #47

Merged
merged 1 commit into from
Jul 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 192 additions & 0 deletions mapper/src/main/java/io/mybatis/mapper/example/ExampleWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ public ExampleWrapper<T, I> set(boolean useSet, Fn<T, Object> fn, Object value)
return useSet ? set(fn, value) : this;
}


/**
* 设置更新字段和值
*
* @param useSet 表达式条件, true 使用,false 不使用
* @param fn 字段
* @param supplier 值构造函数
*/
public ExampleWrapper<T, I> set(boolean useSet, Fn<T, Object> fn, Supplier<Object> supplier) {
return useSet ? set(fn, supplier.get()) : this;
}


/**
* 设置更新字段和值
*
Expand Down Expand Up @@ -248,6 +261,17 @@ public ExampleWrapper<T, I> eq(boolean useCondition, Fn<T, Object> fn, Object va
return useCondition ? eq(fn, value) : this;
}

/**
* 字段 = 值
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
* @param supplier 值构造函数
*/
public ExampleWrapper<T, I> eq(boolean useCondition, Fn<T, Object> fn, Supplier<Object> supplier) {
return useCondition ? eq(fn, supplier.get()) : this;
}

/**
* 字段 = 值
*
Expand All @@ -259,6 +283,17 @@ public ExampleWrapper<T, I> eq(Fn<T, Object> fn, Object value) {
return this;
}

/**
* 字段 != 值
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
* @param supplier 值构造函数
*/
public ExampleWrapper<T, I> ne(boolean useCondition, Fn<T, Object> fn, Supplier<Object> supplier) {
return useCondition ? ne(fn, supplier.get()) : this;
}

/**
* 字段 != 值
*
Expand All @@ -281,6 +316,17 @@ public ExampleWrapper<T, I> ne(Fn<T, Object> fn, Object value) {
return this;
}

/**
* 字段 > 值
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
* @param supplier 值构造函数
*/
public ExampleWrapper<T, I> gt(boolean useCondition, Fn<T, Object> fn, Supplier<Object> supplier) {
return useCondition ? gt(fn, supplier.get()) : this;
}

/**
* 字段 > 值
*
Expand All @@ -303,6 +349,17 @@ public ExampleWrapper<T, I> gt(Fn<T, Object> fn, Object value) {
return this;
}

/**
* 字段 >= 值
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
* @param supplier 值构造函数
*/
public ExampleWrapper<T, I> ge(boolean useCondition, Fn<T, Object> fn, Supplier<Object> supplier) {
return useCondition ? ge(fn, supplier.get()) : this;
}

/**
* 字段 >= 值
*
Expand All @@ -325,6 +382,16 @@ public ExampleWrapper<T, I> ge(Fn<T, Object> fn, Object value) {
return this;
}

/**
* 字段 < 值
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
*/
public ExampleWrapper<T, I> lt(boolean useCondition, Fn<T, Object> fn, Supplier<Object> supplier) {
return useCondition ? lt(fn, supplier.get()) : this;
}

/**
* 字段 < 值
*
Expand Down Expand Up @@ -358,6 +425,17 @@ public ExampleWrapper<T, I> le(boolean useCondition, Fn<T, Object> fn, Object va
return useCondition ? le(fn, value) : this;
}

/**
* 字段 <= 值
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
* @param supplier 值构造函数
*/
public ExampleWrapper<T, I> le(boolean useCondition, Fn<T, Object> fn, Supplier<Object> supplier) {
return useCondition ? le(fn, supplier.get()) : this;
}

/**
* 字段 <= 值
*
Expand All @@ -381,6 +459,18 @@ public ExampleWrapper<T, I> in(boolean useCondition, Fn<T, Object> fn, Iterable
return useCondition ? in(fn, values) : this;
}

/**
* 字段 in (值集合)
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
* @param supplier 值集合构造函数
*/
@SuppressWarnings("rawtypes")
public ExampleWrapper<T, I> in(boolean useCondition, Fn<T, Object> fn, Supplier<Iterable> supplier) {
return useCondition ? in(fn, supplier.get()) : this;
}

/**
* 字段 in (值集合)
*
Expand All @@ -405,6 +495,18 @@ public ExampleWrapper<T, I> notIn(boolean useCondition, Fn<T, Object> fn, Iterab
return useCondition ? notIn(fn, values) : this;
}

/**
* 字段 not in (值集合)
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
* @param supplier 值集合构造函数
*/
@SuppressWarnings("rawtypes")
public ExampleWrapper<T, I> notIn(boolean useCondition, Fn<T, Object> fn, Supplier<Iterable> supplier) {
return useCondition ? notIn(fn, supplier.get()) : this;
}

/**
* 字段 not in (值集合)
*
Expand All @@ -429,6 +531,18 @@ public ExampleWrapper<T, I> between(boolean useCondition, Fn<T, Object> fn, Obje
return useCondition ? between(fn, value1, value2) : this;
}

/**
* 字段 between value1 and value 2
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
* @param supplier1 值1构造函数
* @param supplier2 值2构造函数
*/
public ExampleWrapper<T, I> between(boolean useCondition, Fn<T, Object> fn, Supplier<Object> supplier1, Supplier<Object> supplier2) {
return useCondition ? between(fn, supplier1.get(), supplier2.get()) : this;
}

/**
* 字段 between value1 and value 2
*
Expand All @@ -453,6 +567,18 @@ public ExampleWrapper<T, I> notBetween(boolean useCondition, Fn<T, Object> fn, O
return useCondition ? notBetween(fn, value1, value2) : this;
}

/**
* 字段 not between value1 and value 2
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
* @param supplier1 值1构造函数
* @param supplier2 值2构造函数
*/
public ExampleWrapper<T, I> notBetween(boolean useCondition, Fn<T, Object> fn, Supplier<Object> supplier1, Supplier<Object> supplier2) {
return useCondition ? notBetween(fn, supplier1.get(), supplier2.get()) : this;
}

/**
* 字段 not between value1 and value 2
*
Expand All @@ -476,6 +602,17 @@ public ExampleWrapper<T, I> contains(boolean useCondition, Fn<T, Object> fn, Str
return useCondition ? contains(fn, value) : this;
}

/**
* 字段 like %值%
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
* @param supplier 值构造函数,两侧自动添加 %
*/
public ExampleWrapper<T, I> contains(boolean useCondition, Fn<T, Object> fn, Supplier<String> supplier) {
return useCondition ? contains(fn, supplier.get()) : this;
}

/**
* 字段 like %值%
*
Expand All @@ -498,6 +635,17 @@ public ExampleWrapper<T, I> startsWith(boolean useCondition, Fn<T, Object> fn, S
return useCondition ? startsWith(fn, value) : this;
}

/**
* 字段 like 值%,匹配 value 为前缀的值
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
* @param supplier 值构造函数,右侧自动添加 %
*/
public ExampleWrapper<T, I> startsWith(boolean useCondition, Fn<T, Object> fn, Supplier<String> supplier) {
return useCondition ? startsWith(fn, supplier.get()) : this;
}

/**
* 字段 like 值%,匹配 value 为前缀的值
*
Expand All @@ -520,6 +668,17 @@ public ExampleWrapper<T, I> endsWith(boolean useCondition, Fn<T, Object> fn, Str
return useCondition ? endsWith(fn, value) : this;
}

/**
* 字段 like %值,匹配 value 为后缀的值
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
* @param supplier 值构造函数,左侧自动添加 %
*/
public ExampleWrapper<T, I> endsWith(boolean useCondition, Fn<T, Object> fn, Supplier<String> supplier) {
return useCondition ? endsWith(fn, supplier.get()) : this;
}

/**
* 字段 like %值,匹配 value 为后缀的值
*
Expand All @@ -542,6 +701,17 @@ public ExampleWrapper<T, I> like(boolean useCondition, Fn<T, Object> fn, String
return useCondition ? like(fn, value) : this;
}

/**
* 字段 like 值
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
* @param supplier 值构造函数,需要指定 '%'(多个), '_'(单个) 模糊匹配
*/
public ExampleWrapper<T, I> like(boolean useCondition, Fn<T, Object> fn, Supplier<String> supplier) {
return useCondition ? like(fn, supplier.get()) : this;
}

/**
* 字段 like 值
*
Expand All @@ -564,6 +734,17 @@ public ExampleWrapper<T, I> notLike(boolean useCondition, Fn<T, Object> fn, Stri
return useCondition ? notLike(fn, value) : this;
}

/**
* 字段 not like 值
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param fn 字段对应的 get 方法引用
* @param supplier 值构造函数,需要指定 % 模糊匹配
*/
public ExampleWrapper<T, I> notLike(boolean useCondition, Fn<T, Object> fn, Supplier<String> supplier) {
return useCondition ? notLike(fn, supplier.get()) : this;
}

/**
* 字段 not like 值
*
Expand Down Expand Up @@ -606,6 +787,17 @@ public ExampleWrapper<T, I> anyCondition(boolean useCondition, String condition,
return useCondition ? anyCondition(condition, value) : this;
}

/**
* 手写左边条件,右边用value值
*
* @param useCondition 表达式条件, true 使用,false 不使用
* @param condition 例如 "length(countryname)="
* @param supplier 任意条件值的构造函数
*/
public ExampleWrapper<T, I> anyCondition(boolean useCondition, String condition, Supplier<Object> supplier) {
return useCondition ? anyCondition(condition, supplier.get()) : this;
}

/**
* 手写左边条件,右边用value值
*
Expand Down