From 60b530b8de321bb2403f2225192a9a0e859537ac Mon Sep 17 00:00:00 2001 From: jerry_zheng Date: Tue, 25 Jul 2023 21:12:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20BaseMapper=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20selectOneWithRelationsByIdAs=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/mybatisflex/core/BaseMapper.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java index 25f4627b..ed04c9e4 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java @@ -500,6 +500,20 @@ public interface BaseMapper { return MapperUtil.queryRelations(this, selectOneById(id)); } + /** + * 根据主表主键来查询 1 条数据。 + * @param id 表主键 + * @param asType 接收数据类型 + * @return 实体类数据 + */ + default R selectOneWithRelationsByIdAs(Serializable id, Class asType) { + try { + MappedStatementTypes.setCurrentType(asType); + return (R) selectOneWithRelationsById(id); + } finally { + MappedStatementTypes.clear(); + } + } /** * 根据查询条件来查询 1 条数据。 *