瀏覽代碼

暂时优化这几个

miemie 7 年之前
父節點
當前提交
6a33d3576a

+ 148 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/interfaces/Compare.java

@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.conditions.interfaces;
+
+/**
+ * <p>
+ * 查询条件封装
+ * 比较值
+ * </p>
+ *
+ * @author hubin miemie HCL
+ * @since 2017-05-26
+ */
+public interface Compare<This, R> {
+
+    /**
+     * 等于 =
+     */
+    default This eq(R column, Object val) {
+        return eq(true, column, val);
+    }
+
+    /**
+     * 等于 =
+     */
+    This eq(boolean condition, R column, Object val);
+
+    /**
+     * 不等于 <>
+     */
+    default This ne(R column, Object val) {
+        return ne(true, column, val);
+    }
+
+    /**
+     * 不等于 <>
+     */
+    This ne(boolean condition, R column, Object val);
+
+    /**
+     * 大于 >
+     */
+    default This gt(R column, Object val) {
+        return gt(true, column, val);
+    }
+
+    /**
+     * 大于 >
+     */
+    This gt(boolean condition, R column, Object val);
+
+    /**
+     * 大于等于 >=
+     */
+    default This ge(R column, Object val) {
+        return ge(true, column, val);
+    }
+
+    /**
+     * 大于等于 >=
+     */
+    This ge(boolean condition, R column, Object val);
+
+    /**
+     * 小于 <
+     */
+    default This lt(R column, Object val) {
+        return lt(true, column, val);
+    }
+
+    /**
+     * 小于 <
+     */
+    This lt(boolean condition, R column, Object val);
+
+    /**
+     * 小于等于 <=
+     */
+    default This le(R column, Object val) {
+        return le(true, column, val);
+    }
+
+    /**
+     * 小于等于 <=
+     */
+    This le(boolean condition, R column, Object val);
+
+    /**
+     * LIKE '%值%'
+     */
+    default This like(R column, Object val) {
+        return like(true, column, val);
+    }
+
+    /**
+     * LIKE '%值%'
+     */
+    This like(boolean condition, R column, Object val);
+
+    /**
+     * NOT LIKE '%值%'
+     */
+    default This notLike(R column, Object val) {
+        return notLike(true, column, val);
+    }
+
+    /**
+     * NOT LIKE '%值%'
+     */
+    This notLike(boolean condition, R column, Object val);
+
+    /**
+     * LIKE '%值'
+     */
+    default This likeLeft(R column, Object val) {
+        return likeLeft(true, column, val);
+    }
+
+    /**
+     * LIKE '%值'
+     */
+    This likeLeft(boolean condition, R column, Object val);
+
+    /**
+     * LIKE '值%'
+     */
+    default This likeRight(R column, Object val) {
+        return likeRight(true, column, val);
+    }
+
+    /**
+     * LIKE '值%'
+     */
+    This likeRight(boolean condition, R column, Object val);
+}

+ 125 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/interfaces/Join.java

@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.conditions.interfaces;
+
+/**
+ * <p>
+ * 查询条件封装
+ * 拼接
+ * </p>
+ *
+ * @author hubin miemie HCL
+ * @since 2017-05-26
+ */
+public interface Join<This> {
+
+    /**
+     * 拼接 AND
+     */
+    default This and() {
+        return and(true);
+    }
+
+    /**
+     * 拼接 AND
+     */
+    This and(boolean condition);
+
+    /**
+     * 拼接 OR
+     */
+    default This or() {
+        return or(true);
+    }
+
+    /**
+     * 拼接 OR
+     */
+    This or(boolean condition);
+
+    /**
+     * 拼接 IN ( sql 语句 )
+     * 例: in("1,2,3,4,5,6")
+     */
+    default This in(String sql) {
+        return in(true, sql);
+    }
+
+    /**
+     * 拼接 IN ( sql 语句 )
+     * 例: in("1,2,3,4,5,6")
+     */
+    This in(boolean condition, String sql);
+
+    /**
+     * 拼接 NOT IN ( sql 语句 )
+     * 例: notIn("1,2,3,4,5,6")
+     */
+    default This notIn(String sql) {
+        return notIn(true, sql);
+    }
+
+    /**
+     * 拼接 NOT IN ( sql 语句 )
+     * 例: notIn("1,2,3,4,5,6")
+     */
+    This notIn(boolean condition, String sql);
+
+    /**
+     * 拼接 sql
+     * 例: apply("date_format(column,'%Y-%m-%d') = '2008-08-08'")
+     */
+    default This apply(String applySql) {
+        return apply(true, applySql);
+    }
+
+    /**
+     * 拼接 sql
+     * 例: apply("date_format(column,'%Y-%m-%d') = '2008-08-08'")
+     */
+    This apply(boolean condition, String applySql);
+
+    /**
+     * 拼接 sql
+     * 例: apply("date_format(column,'%Y-%m-%d') = {0}", LocalDate.now())
+     */
+    default This apply(String applySql, Object... value) {
+        return apply(true, applySql, value);
+    }
+
+    /**
+     * 拼接 sql
+     * 例: apply("date_format(column,'%Y-%m-%d') = {0}", LocalDate.now())
+     */
+    This apply(boolean condition, String applySql, Object... value);
+
+    /**
+     * LAST 拼接在 SQL 末尾
+     * 例: last("limit 10")
+     */
+    @Deprecated
+    default This last(String lastSql) {
+        return last(true, lastSql);
+    }
+
+    /**
+     * LAST 拼接在 SQL 末尾
+     */
+    @Deprecated
+    default This last(boolean condition, String lastSql) {
+        return apply(true, lastSql);
+    }
+}

+ 54 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/interfaces/Nested.java

@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.core.conditions.interfaces;
+
+import java.util.function.Function;
+
+/**
+ * <p>
+ * 查询条件封装
+ * 嵌套
+ * </p>
+ *
+ * @author hubin miemie HCL
+ * @since 2017-05-26
+ */
+public interface Nested<This> {
+
+    /**
+     * AND 嵌套
+     */
+    default This and(Function<This, This> func) {
+        return and(true, func);
+    }
+
+    /**
+     * AND 嵌套
+     */
+    This and(boolean condition, Function<This, This> func);
+
+    /**
+     * OR 嵌套
+     */
+    default This or(Function<This, This> func) {
+        return or(true, func);
+    }
+
+    /**
+     * OR 嵌套
+     */
+    This or(boolean condition, Function<This, This> func);
+}

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/select/EntityWrapper.java

@@ -67,7 +67,7 @@ public class EntityWrapper<T> extends AbstractWrapper<T, String, EntityWrapper<T
         if (StringUtils.isNotEmpty(sqlSelect)) {
             this.sqlSelect = sqlSelect;
         }
-        return typedThis();
+        return typedThis;
     }
 
     public LambdaEntityWrapper<T> stream() {

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/select/LambdaEntityWrapper.java

@@ -69,7 +69,7 @@ public class LambdaEntityWrapper<T> extends AbstractLambdaWrapper<T, LambdaEntit
         for (Property<T, ?> column : columns) {
             sqlSelect.add(this.columnToString(column));
         }
-        return typedThis();
+        return typedThis;
     }
 
 

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/update/LambdaUpdateWrapper.java

@@ -64,7 +64,7 @@ public class LambdaUpdateWrapper<T> extends AbstractLambdaWrapper<T, LambdaUpdat
         if (condition) {
             sqlSet.add(String.format("%s=%s", columnToString(column), formatSql("{0}", val)));
         }
-        return typedThis();
+        return typedThis;
     }
 
     @Override

+ 2 - 2
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/update/UpdateWrapper.java

@@ -95,7 +95,7 @@ public class UpdateWrapper<T> extends AbstractWrapper<T, String, UpdateWrapper<T
         if (condition) {
             sqlSet.add(String.format("%s=%s", column, formatSql("{0}", val)));
         }
-        return typedThis();
+        return typedThis;
     }
 
     /**
@@ -108,7 +108,7 @@ public class UpdateWrapper<T> extends AbstractWrapper<T, String, UpdateWrapper<T
      */
     public UpdateWrapper<T> setSql(String sql) {
         sqlSet.add(sql);
-        return typedThis();
+        return typedThis;
     }
 
     @Override