I have an object that contains as attribute other two object, like this:
public class A {
private B b;
private C c;
....
}
B and C have already their result maps in separated file .xml with mybatis.
I have a join query that return A and I need to create a new result map (in mybatis) wich contains the resultMap of B and the resultMap of C, but i don't want to rewrite the previous resultMaps.
Is there a way to merge the two resultMaps ?
I have an Example to create a resultMap
which contains other resultMaps
.
<resultMap id="articleMap" type="com.xxx.tinybbs.entity.Article">
<id column="ID" jdbcType="INTEGER" property="ID" />
<result column="title" jdbcType="VARCHAR" property="title" />
<result column="createTime" jdbcType="TIMESTAMP" property="createTime" />
<result column="pid" jdbcType="INTEGER" property="pid" />
<result column="authorId" jdbcType="INTEGER" property="authorId" />
<result column="boardId" jdbcType="INTEGER" property="boardId" />
<result column="sourceIp" jdbcType="VARCHAR" property="sourceIp" />
<association property="board" javaType="com.xxx.tinybbs.entity.Board" column="boardId" resultMap="com.xxx.tinybbs.dao.BoardMapper.BaseResultMap">
</association>
</resultMap>
<select id="getFullArticleInfo" parameterType="int" resultMap="articleMap">
select article.*, board.* from article left join board on article.boardId = board.id where article.id =#{id};
</select>
Note that, import other resultMap resultMap="com.xxx.tinybbs.dao.BoardMapper.BaseResultMap"
, com.xxx.tinybbs.dao.BoardMapper
is the namespace
of other mapper.xml
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.