Mybatis resultMap支持继承

一、代码

映射domain为继承关系

public class CocTreeNode extends CocBean implements TreeNode {
 
  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属性。

"CocBeanResult" type="CocBean">
    "name" column="NAME"/>
    "volume" column="VOLUME"/>

 
"simpleRow" type="CocTreeNode" extends="CocBeanResult">
    "level1" column="LEVEL1"/>
    "level2" column="LEVEL2"/>

 

转载于:https://www.cnblogs.com/socketqiang/p/10862037.html

你可能感兴趣的:(Mybatis resultMap支持继承)