Mybatis resultMap支持继承

一、代码

映射domain为继承关系

public class CocTreeNode extends CocBean implements TreeNode<CocTreeNode> {

  private String level1, level2;

  public void setLevel1(String level1){...}
  public void setLevel2(String level2){...}

  public String getLevel1(){...}
  public String getLevel1(){...}

}

public class CocBean {

  protected String name;
  protected Double volume;

  public void setName(String name){...}
  public void setVolume(Double volume){...}

  public String getName(){...}
  public Double getVolume(){...}

}

二、映射xml文件

利用resultMap的extends属性。

<resultMap id="CocBeanResult" type="CocBean">
    <result property="name" column="NAME"/>
    <result property="volume" column="VOLUME"/>
</resultMap>

<resultMap id="simpleRow" type="CocTreeNode" extends="CocBeanResult">
    <result property="level1" column="LEVEL1"/>
    <result property="level2" column="LEVEL2"/>
</resultMap>



参考:

http://stackoverflow.com/questions/13734779/mybatis-inherited-properties-not-being-mapped

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页