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 条数据。 *