在MyBatis中,类扩展可以通过使用resultMap的方式来实现。具体步骤如下:
<resultMap id="BaseResultMap" type="com.example.BaseEntity"> <id column="id" property="id" /> <result column="name" property="name" /> </resultMap> <resultMap id="ExtendedResultMap" type="com.example.ExtendedEntity" extends="BaseResultMap"> <result column="age" property="age" /> </resultMap> <select id="selectExtendedEntity" resultMap="ExtendedResultMap"> SELECT id, name, age FROM extended_entity </select> 通过以上步骤,我们就可以实现类扩展的功能,在查询结果中同时包含BaseEntity和ExtendedEntity的属性。需要注意的是,在扩展的结果映射中可以添加新的属性,但不能覆盖或修改已有的属性映射。