浏览代码

Merge branch '3.0' into github-3.0

hubin 4 年之前
父节点
当前提交
1ed4c7d45e

+ 20 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/query/LambdaQueryWrapper.java

@@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
 import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
 import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
 import com.baomidou.mybatisplus.core.toolkit.ArrayUtils;
+import com.baomidou.mybatisplus.core.toolkit.Assert;
 import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
 
 import java.util.Map;
@@ -110,7 +111,25 @@ public class LambdaQueryWrapper<T> extends AbstractLambdaWrapper<T, LambdaQueryW
     @Override
     public LambdaQueryWrapper<T> select(Class<T> entityClass, Predicate<TableFieldInfo> predicate) {
         super.setEntityClass(entityClass);
-        this.sqlSelect.setStringValue(TableInfoHelper.getTableInfo(getEntityClass()).chooseSelect(predicate));
+        return select(predicate);
+    }
+
+    /**
+     * 过滤查询的字段信息(主键除外!)
+     * <p>例1: 只要 java 字段名以 "test" 开头的             -> select(i -&gt; i.getProperty().startsWith("test"))</p>
+     * <p>例2: 只要 java 字段属性是 CharSequence 类型的     -> select(TableFieldInfo::isCharSequence)</p>
+     * <p>例3: 只要 java 字段没有填充策略的                 -> select(i -&gt; i.getFieldFill() == FieldFill.DEFAULT)</p>
+     * <p>例4: 要全部字段                                   -> select(i -&gt; true)</p>
+     * <p>例5: 只要主键字段                                 -> select(i -&gt; false)</p>
+     *
+     * @param predicate 过滤方式
+     * @return this
+     */
+    @Override
+    public LambdaQueryWrapper<T> select(Predicate<TableFieldInfo> predicate) {
+        Class<T> entityClass = getEntityClass();
+        Assert.notNull(entityClass, "entityClass can not be null");
+        this.sqlSelect.setStringValue(TableInfoHelper.getTableInfo(entityClass).chooseSelect(predicate));
         return typedThis;
     }