简体   繁体   English

用mybatis加入不同的结果图

[英]Join different result map with mybatis

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. B 和 C 已经在 mybatis 的单独文件 .xml 中拥有了他们的结果映射。

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.我有一个返回 A 的连接查询,我需要创建一个新的结果映射(在 mybatis 中),其中包含 B 的 resultMap 和 C 的 resultMap,但我不想重写以前的 resultMap。

Is there a way to merge the two resultMaps ?有没有办法合并两个 resultMap ?

I have an Example to create a resultMap which contains other resultMaps .我有一个实施例创建resultMap包含其他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注意,导入其他 resultMap resultMap="com.xxx.tinybbs.dao.BoardMapper.BaseResultMap"com.xxx.tinybbs.dao.BoardMapper是其他 mapper.xml 的namespace

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM