From 7744f7c3a088b4bbefd782f28b5bbceed2e868af Mon Sep 17 00:00:00 2001 From: yulichang <570810310@qq.com> Date: Wed, 21 Dec 2022 14:49:48 +0800 Subject: [PATCH] =?UTF-8?q?selectAs=E9=87=8D=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yulichang/wrapper/interfaces/Query.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java index e4178aa..3126b4d 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Query.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.TableFieldInfo; import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.metadata.TableInfoHelper; import com.baomidou.mybatisplus.core.toolkit.Assert; +import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.github.yulichang.toolkit.LambdaUtils; import com.github.yulichang.toolkit.MPJReflectionKit; @@ -71,6 +72,28 @@ public interface Query extends Serializable { return getChildren(); } + /** + * String 查询 + * + * @param column 列 + */ + default Children select(String column, SFunction alias) { + getSelectColum().add(new SelectString(column + Constants.AS + LambdaUtils.getName(alias))); + return getChildren(); + } + + /** + * String 查询 + * + * @param column 列 + */ + default Children select(String index, SFunction column, SFunction alias) { + Map cacheMap = ColumnCache.getMapField(LambdaUtils.getEntityClass(column)); + SelectCache cache = cacheMap.get(LambdaUtils.getName(column)); + getSelectColum().add(new SelectString(index + Constants.DOT + cache.getColumn() + Constants.AS + LambdaUtils.getName(alias))); + return getChildren(); + } + /** * 说明: * 比如我们需要查询用户表有10个字段,然而我们只需要3个就够了,用mybatis-plus提供的select