mybatis resultMap include
时间: 2023-09-01 21:12:12 浏览: 199
MyBatis provides a feature called "resultMap" to map the query results to objects. It allows you to define how the columns in the result set should be mapped to the properties of your Java objects.
To include the result mappings from another resultMap, you can use the "include" element within the resultMap definition. Here's an example:
```xml
<resultMap id="BaseResultMap" type="com.example.User">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
</resultMap>
<resultMap id="ExtendedResultMap" type="com.example.ExtendedUser" extends="BaseResultMap">
<result property="extraProperty" column="extra_column"/>
</resultMap>
```
In the above example, the "ExtendedResultMap" includes the mappings from the "BaseResultMap" using the "extends" attribute. It then adds an additional result mapping for the "extraProperty" field.
This allows you to reuse and extend existing result maps, making your code more maintainable and reducing duplication.
阅读全文