From 571a3d1142b4b0dbaab7b618b0171ec069ffdf1f Mon Sep 17 00:00:00 2001 From: darren Date: Fri, 8 Jul 2022 18:42:23 +0800 Subject: [PATCH] =?UTF-8?q?ExampleWrapper=20condition=20=E7=B3=BB=E5=88=97?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=96=B0=E5=A2=9E=20Supplier=20=E9=87=8D?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/example/ExampleWrapper.java | 192 ++++++++++++++++++ 1 file changed, 192 insertions(+) diff --git a/mapper/src/main/java/io/mybatis/mapper/example/ExampleWrapper.java b/mapper/src/main/java/io/mybatis/mapper/example/ExampleWrapper.java index 590c5b1..620aff3 100644 --- a/mapper/src/main/java/io/mybatis/mapper/example/ExampleWrapper.java +++ b/mapper/src/main/java/io/mybatis/mapper/example/ExampleWrapper.java @@ -186,6 +186,19 @@ public ExampleWrapper set(boolean useSet, Fn fn, Object value) return useSet ? set(fn, value) : this; } + + /** + * 设置更新字段和值 + * + * @param useSet 表达式条件, true 使用,false 不使用 + * @param fn 字段 + * @param supplier 值构造函数 + */ + public ExampleWrapper set(boolean useSet, Fn fn, Supplier supplier) { + return useSet ? set(fn, supplier.get()) : this; + } + + /** * 设置更新字段和值 * @@ -248,6 +261,17 @@ public ExampleWrapper eq(boolean useCondition, Fn fn, Object va return useCondition ? eq(fn, value) : this; } + /** + * 字段 = 值 + * + * @param useCondition 表达式条件, true 使用,false 不使用 + * @param fn 字段对应的 get 方法引用 + * @param supplier 值构造函数 + */ + public ExampleWrapper eq(boolean useCondition, Fn fn, Supplier supplier) { + return useCondition ? eq(fn, supplier.get()) : this; + } + /** * 字段 = 值 * @@ -259,6 +283,17 @@ public ExampleWrapper eq(Fn fn, Object value) { return this; } + /** + * 字段 != 值 + * + * @param useCondition 表达式条件, true 使用,false 不使用 + * @param fn 字段对应的 get 方法引用 + * @param supplier 值构造函数 + */ + public ExampleWrapper ne(boolean useCondition, Fn fn, Supplier supplier) { + return useCondition ? ne(fn, supplier.get()) : this; + } + /** * 字段 != 值 * @@ -281,6 +316,17 @@ public ExampleWrapper ne(Fn fn, Object value) { return this; } + /** + * 字段 > 值 + * + * @param useCondition 表达式条件, true 使用,false 不使用 + * @param fn 字段对应的 get 方法引用 + * @param supplier 值构造函数 + */ + public ExampleWrapper gt(boolean useCondition, Fn fn, Supplier supplier) { + return useCondition ? gt(fn, supplier.get()) : this; + } + /** * 字段 > 值 * @@ -303,6 +349,17 @@ public ExampleWrapper gt(Fn fn, Object value) { return this; } + /** + * 字段 >= 值 + * + * @param useCondition 表达式条件, true 使用,false 不使用 + * @param fn 字段对应的 get 方法引用 + * @param supplier 值构造函数 + */ + public ExampleWrapper ge(boolean useCondition, Fn fn, Supplier supplier) { + return useCondition ? ge(fn, supplier.get()) : this; + } + /** * 字段 >= 值 * @@ -325,6 +382,16 @@ public ExampleWrapper ge(Fn fn, Object value) { return this; } + /** + * 字段 < 值 + * + * @param useCondition 表达式条件, true 使用,false 不使用 + * @param fn 字段对应的 get 方法引用 + */ + public ExampleWrapper lt(boolean useCondition, Fn fn, Supplier supplier) { + return useCondition ? lt(fn, supplier.get()) : this; + } + /** * 字段 < 值 * @@ -358,6 +425,17 @@ public ExampleWrapper le(boolean useCondition, Fn fn, Object va return useCondition ? le(fn, value) : this; } + /** + * 字段 <= 值 + * + * @param useCondition 表达式条件, true 使用,false 不使用 + * @param fn 字段对应的 get 方法引用 + * @param supplier 值构造函数 + */ + public ExampleWrapper le(boolean useCondition, Fn fn, Supplier supplier) { + return useCondition ? le(fn, supplier.get()) : this; + } + /** * 字段 <= 值 * @@ -381,6 +459,18 @@ public ExampleWrapper in(boolean useCondition, Fn fn, Iterable return useCondition ? in(fn, values) : this; } + /** + * 字段 in (值集合) + * + * @param useCondition 表达式条件, true 使用,false 不使用 + * @param fn 字段对应的 get 方法引用 + * @param supplier 值集合构造函数 + */ + @SuppressWarnings("rawtypes") + public ExampleWrapper in(boolean useCondition, Fn fn, Supplier supplier) { + return useCondition ? in(fn, supplier.get()) : this; + } + /** * 字段 in (值集合) * @@ -405,6 +495,18 @@ public ExampleWrapper notIn(boolean useCondition, Fn fn, Iterab return useCondition ? notIn(fn, values) : this; } + /** + * 字段 not in (值集合) + * + * @param useCondition 表达式条件, true 使用,false 不使用 + * @param fn 字段对应的 get 方法引用 + * @param supplier 值集合构造函数 + */ + @SuppressWarnings("rawtypes") + public ExampleWrapper notIn(boolean useCondition, Fn fn, Supplier supplier) { + return useCondition ? notIn(fn, supplier.get()) : this; + } + /** * 字段 not in (值集合) * @@ -429,6 +531,18 @@ public ExampleWrapper between(boolean useCondition, Fn 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 between(boolean useCondition, Fn fn, Supplier supplier1, Supplier supplier2) { + return useCondition ? between(fn, supplier1.get(), supplier2.get()) : this; + } + /** * 字段 between value1 and value 2 * @@ -453,6 +567,18 @@ public ExampleWrapper notBetween(boolean useCondition, Fn 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 notBetween(boolean useCondition, Fn fn, Supplier supplier1, Supplier supplier2) { + return useCondition ? notBetween(fn, supplier1.get(), supplier2.get()) : this; + } + /** * 字段 not between value1 and value 2 * @@ -476,6 +602,17 @@ public ExampleWrapper contains(boolean useCondition, Fn fn, Str return useCondition ? contains(fn, value) : this; } + /** + * 字段 like %值% + * + * @param useCondition 表达式条件, true 使用,false 不使用 + * @param fn 字段对应的 get 方法引用 + * @param supplier 值构造函数,两侧自动添加 % + */ + public ExampleWrapper contains(boolean useCondition, Fn fn, Supplier supplier) { + return useCondition ? contains(fn, supplier.get()) : this; + } + /** * 字段 like %值% * @@ -498,6 +635,17 @@ public ExampleWrapper startsWith(boolean useCondition, Fn fn, S return useCondition ? startsWith(fn, value) : this; } + /** + * 字段 like 值%,匹配 value 为前缀的值 + * + * @param useCondition 表达式条件, true 使用,false 不使用 + * @param fn 字段对应的 get 方法引用 + * @param supplier 值构造函数,右侧自动添加 % + */ + public ExampleWrapper startsWith(boolean useCondition, Fn fn, Supplier supplier) { + return useCondition ? startsWith(fn, supplier.get()) : this; + } + /** * 字段 like 值%,匹配 value 为前缀的值 * @@ -520,6 +668,17 @@ public ExampleWrapper endsWith(boolean useCondition, Fn fn, Str return useCondition ? endsWith(fn, value) : this; } + /** + * 字段 like %值,匹配 value 为后缀的值 + * + * @param useCondition 表达式条件, true 使用,false 不使用 + * @param fn 字段对应的 get 方法引用 + * @param supplier 值构造函数,左侧自动添加 % + */ + public ExampleWrapper endsWith(boolean useCondition, Fn fn, Supplier supplier) { + return useCondition ? endsWith(fn, supplier.get()) : this; + } + /** * 字段 like %值,匹配 value 为后缀的值 * @@ -542,6 +701,17 @@ public ExampleWrapper like(boolean useCondition, Fn fn, String return useCondition ? like(fn, value) : this; } + /** + * 字段 like 值 + * + * @param useCondition 表达式条件, true 使用,false 不使用 + * @param fn 字段对应的 get 方法引用 + * @param supplier 值构造函数,需要指定 '%'(多个), '_'(单个) 模糊匹配 + */ + public ExampleWrapper like(boolean useCondition, Fn fn, Supplier supplier) { + return useCondition ? like(fn, supplier.get()) : this; + } + /** * 字段 like 值 * @@ -564,6 +734,17 @@ public ExampleWrapper notLike(boolean useCondition, Fn fn, Stri return useCondition ? notLike(fn, value) : this; } + /** + * 字段 not like 值 + * + * @param useCondition 表达式条件, true 使用,false 不使用 + * @param fn 字段对应的 get 方法引用 + * @param supplier 值构造函数,需要指定 % 模糊匹配 + */ + public ExampleWrapper notLike(boolean useCondition, Fn fn, Supplier supplier) { + return useCondition ? notLike(fn, supplier.get()) : this; + } + /** * 字段 not like 值 * @@ -606,6 +787,17 @@ public ExampleWrapper anyCondition(boolean useCondition, String condition, return useCondition ? anyCondition(condition, value) : this; } + /** + * 手写左边条件,右边用value值 + * + * @param useCondition 表达式条件, true 使用,false 不使用 + * @param condition 例如 "length(countryname)=" + * @param supplier 任意条件值的构造函数 + */ + public ExampleWrapper anyCondition(boolean useCondition, String condition, Supplier supplier) { + return useCondition ? anyCondition(condition, supplier.get()) : this; + } + /** * 手写左边条件,右边用value值 *