浏览代码

思路=丝绸之路进化

125473094@qq.com 7 年之前
父节点
当前提交
da54573dc3

+ 2 - 19
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/LambdaTest/EntityWrappers.java

@@ -7,25 +7,8 @@ package com.baomidou.mybatisplus.core.test.LambdaTest;
  */
 public class EntityWrappers<T> extends Wrappers<EntityWrappers<T>, String, T> {
 
-    private T entity;
-
-    @Override
-    public T getEntity() {
-        return entity;
-    }
-
-    @Override
-    public EntityWrappers<T> where(boolean condition, String sqlWhere, Object... params) {
-        return null;
-    }
-
-    @Override
-    public EntityWrappers<T> eq(boolean condition, String s, Object params) {
-        return null;
-    }
-
     @Override
-    public String getSqlSegment() {
-        return null;
+    String getColumn(String s) {
+        return s;
     }
 }

+ 8 - 19
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/LambdaTest/LambdaEntityWrapper.java

@@ -1,30 +1,19 @@
 package com.baomidou.mybatisplus.core.test.LambdaTest;
 
-import java.util.function.Function;
+import com.baomidou.mybatisplus.core.toolkit.LambdaUtils;
+import com.baomidou.mybatisplus.core.toolkit.support.SerializedFunction;
+import com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda;
 
 /**
  * @author ming
  * @Date 2018/5/10
  */
-public class LambdaEntityWrapper<T> extends Wrappers<LambdaEntityWrapper<T>, Function<T, ?>, T> {
+public class LambdaEntityWrapper<T> extends Wrappers<LambdaEntityWrapper<T>, SerializedFunction<T, ?>, T> {
 
     @Override
-    public T getEntity() {
-        return null;
-    }
-
-    @Override
-    public LambdaEntityWrapper<T> where(boolean condition, String sqlWhere, Object... params) {
-        return null;
-    }
-
-    @Override
-    public LambdaEntityWrapper<T> eq(boolean condition, Function<T, ?> trFunction, Object params) {
-        return null;
-    }
-
-    @Override
-    public String getSqlSegment() {
-        return null;
+    String getColumn(SerializedFunction<T, ?> tFunction) {
+        //todo 能执行?
+        SerializedLambda resolve = LambdaUtils.resolve(tFunction);
+        return resolve.getImplMethodName();
     }
 }

+ 32 - 4
mybatis-plus-core/src/test/java/com/baomidou/mybatisplus/core/test/LambdaTest/Wrappers.java

@@ -5,18 +5,46 @@ package com.baomidou.mybatisplus.core.test.LambdaTest;
  * @Date 2018/5/10
  * @This 自己的实现类
  * @R 入参类型
+ * @T 实体类
  */
 public abstract class Wrappers<This, R, T> {
 
-    abstract T getEntity();
+    private T entity;
 
-    abstract This where(boolean condition, String sqlWhere, Object... params);
+    public T getEntity() {
+        return entity;
+    }
+
+    @SuppressWarnings("unchecked")
+    public This setEntity(T t){
+        entity = t;
+        return (This) this;
+    }
+
+    abstract String getColumn(R r);
+
+    @SuppressWarnings("unchecked")
+    This where(boolean condition, String sqlWhere, Object... params) {
+        //todo 一通操作组装成sql
+        return (This) this;
+    }
 
     This eq(R r, Object params) {
         return eq(true, r, params);
     }
 
-    abstract This eq(boolean condition, R r, Object params);
+    @SuppressWarnings("unchecked")
+    This eq(boolean condition, R r, Object params) {
+        //todo 一通操作组装成sql
+        if (condition) {
+            // todo 咔咔咔
+            getColumn(r);//todo 这是获取到的字段名 user_id
+        }
+        return (This) this;
+    }
 
-    abstract String getSqlSegment();
+    String getSqlSegment() {
+        //SQL 片段
+        return null;
+    }
 }