浏览代码

去除'.and()'接口,'.and(boolean)'的修饰符改为'protected'

miemie 7 年之前
父节点
当前提交
43cd073e78

+ 14 - 11
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/AbstractWrapper.java

@@ -108,7 +108,6 @@ public abstract class AbstractWrapper<T, R, This extends AbstractWrapper<T, R, T
     public This allEq(boolean condition, Map<R, Object> params) {
         if (condition && CollectionUtils.isNotEmpty(params)) {
             params.forEach((k, v) -> {
-                and();
                 if (StringUtils.checkValNotNull(v)) {
                     eq(k, v);
                 } else {
@@ -129,7 +128,7 @@ public abstract class AbstractWrapper<T, R, This extends AbstractWrapper<T, R, T
      * put("name", "baomidou");
      * put("address", null);
      * }};
-     *
+     * <p>
      * 去除值为null的元素,可以这么写:
      * allEq((key,value)-> null!= value, params);
      * 只加入id ,name:
@@ -147,7 +146,6 @@ public abstract class AbstractWrapper<T, R, This extends AbstractWrapper<T, R, T
         if (condition && CollectionUtils.isNotEmpty(params)) {
             params.forEach((key, value) -> {
                 if (filter.test(key, value)) {
-                    and();
                     if (null == value) {
                         isNull(key);
                     } else {
@@ -280,14 +278,6 @@ public abstract class AbstractWrapper<T, R, This extends AbstractWrapper<T, R, T
         return addNestedCondition(condition, func);
     }
 
-    /**
-     * 拼接 AND
-     */
-    @Override
-    public This and(boolean condition) {
-        return doIt(condition, AND);
-    }
-
     /**
      * 拼接 OR
      */
@@ -426,12 +416,25 @@ public abstract class AbstractWrapper<T, R, This extends AbstractWrapper<T, R, T
     }
 
     /**
+     * <p>
+     * 内部自用
+     * </p>
      * NOT 关键词
      */
     protected This not(boolean condition) {
         return doIt(condition, NOT);
     }
 
+    /**
+     * <p>
+     * 内部自用
+     * </p>
+     * 拼接 AND
+     */
+    protected This and(boolean condition) {
+        return doIt(condition, AND);
+    }
+
     /**
      * <p>
      * 普通查询条件

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

@@ -28,18 +28,6 @@ import java.io.Serializable;
  */
 public interface Join<This> extends Serializable {
 
-    /**
-     * 拼接 AND
-     */
-    default This and() {
-        return and(true);
-    }
-
-    /**
-     * 拼接 AND
-     */
-    This and(boolean condition);
-
     /**
      * 拼接 OR
      */

+ 8 - 17
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/WrapperTest.java

@@ -37,7 +37,7 @@ public class WrapperTest {
     public void test() {
         Wrapper<User> wrapper = new QueryWrapper<User>().lambda().eq(User::getName, 123)
             .or(c -> c.eq(User::getRoleId, 1).eq(User::getId, 2))
-            .and().eq(User::getId, 1);
+            .eq(User::getId, 1);
         log(wrapper.getSqlSegment());
 
     }
@@ -46,8 +46,8 @@ public class WrapperTest {
     public void test1() {
         QueryWrapper<User> ew = new QueryWrapper<User>()
             .eq("xxx", 123)
-            .and(i -> i.eq("andx", 65444).and().le("ande", 66666))
-            .and().ne("xxx", 222);
+            .and(i -> i.eq("andx", 65444).le("ande", 66666))
+            .ne("xxx", 222);
         log(ew.getSqlSegment());
         ew.getParamNameValuePairs().forEach((k, v) -> System.out.println("key = " + k + " ; value = " + v));
     }
@@ -57,8 +57,8 @@ public class WrapperTest {
         UpdateWrapper<User> ew = new UpdateWrapper<User>()
             .set("name", "三毛").set("id", 1)
             .eq("xxx", 123)
-            .and(i -> i.eq("andx", 65444).and().le("ande", 66666))
-            .and().ne("xxx", 222);
+            .and(i -> i.eq("andx", 65444).le("ande", 66666))
+            .ne("xxx", 222);
         log(ew.getSqlSet());
         log(ew.getSqlSegment());
     }
@@ -66,30 +66,21 @@ public class WrapperTest {
     @Test
     public void test3() {
         UpdateWrapper<User> ew = new UpdateWrapper<User>()
-            .setSql("abc=1,def=2").eq("id", 1).and().ge("age", 3);
+            .setSql("abc=1,def=2").eq("id", 1).ge("age", 3);
         log(ew.getSqlSet());
         log(ew.getSqlSegment());
     }
 
     @Test
     public void testQueryWrapper() {
-        logSqlSegment("去除第一个 and,以及自动拼接 and,以及手动拼接 and", new QueryWrapper<User>().and()
-            .ge("age", 3).and().ge("age", 3).ge("age", 3));
-
         logSqlSegment("去除第一个 or,以及自动拼接 and,以及手动拼接 or", new QueryWrapper<User>().or()
             .ge("age", 3).or().ge("age", 3).ge("age", 3));
 
-        logSqlSegment("多个 and 相连接,去除多余的 and", new QueryWrapper<User>()
-            .ge("age", 3).and().and().and().ge("age", 3).and().and().ge("age", 3));
-
         logSqlSegment("多个 or 相连接,去除多余的 or", new QueryWrapper<User>()
             .ge("age", 3).or().or().or().ge("age", 3).or().or().ge("age", 3));
 
-        logSqlSegment("多个 and或者 or 相连接,取最后一个", new QueryWrapper<User>()
-            .ge("age", 3).and().or().and().ge("age", 3).and().or().ge("age", 3));
-
-        logSqlSegment("嵌套测试,套内外自动拼接 and,去除套内第一个 and", new QueryWrapper<User>()
-            .eq("id", 11).and(i -> i.and().eq("id", 1)).eq("id", 1));
+        logSqlSegment("嵌套测试,套内外自动拼接 and", new QueryWrapper<User>()
+            .eq("id", 11).and(i -> i.eq("id", 1)).eq("id", 1));
 
         logSqlSegment("嵌套测试,套内外手动拼接 or,去除套内第一个 or", new QueryWrapper<User>()
             .eq("id", 11).or(i -> i.or().eq("id", 1)).or().eq("id", 1));

+ 3 - 5
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/MysqlTestDataMapperTest.java

@@ -43,9 +43,7 @@ public class MysqlTestDataMapperTest {
     public void commonSelectList() {
         println(testDataMapper.selectList(new QueryWrapper<TestData>()
             .eq("id", 1L)
-            .and()
             .like("test_str", 1)
-            .and()
             .between("test_double", 1L, 2L)));
     }
 
@@ -57,9 +55,9 @@ public class MysqlTestDataMapperTest {
             .or(i -> i.eq(TestData::getTestInt, 1)
                 .or().eq(TestData::getTestDate, 1)
             )
-            .and().eq(TestData::getTestBoolean, true)
-            .and().eq(TestData::getTestDate, LocalDate.of(2008, 8, 8))
-            .and().between(TestData::getTestDate, LocalDate.of(2008, 1, 1),
+            .eq(TestData::getTestBoolean, true)
+            .eq(TestData::getTestDate, LocalDate.of(2008, 8, 8))
+            .between(TestData::getTestDate, LocalDate.of(2008, 1, 1),
                 LocalDate.of(2008, 12, 12))));
     }