Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Mybatis-未映射继承的属性_Java_Generics_Mybatis - Fatal编程技术网

Java Mybatis-未映射继承的属性

Java Mybatis-未映射继承的属性,java,generics,mybatis,Java,Generics,Mybatis,我有两个类,其中一个继承另一个。我试图将我的结果集映射到子类,而Mybatis忽略了超类上的属性(setter也在超类上) 代码如下: public class CocTreeNode extends CocBean implements TreeNode<CocTreeNode> { private String level1, level2; public void setLevel1(String level1){...} public void setLeve

我有两个类,其中一个继承另一个。我试图将我的结果集映射到子类,而Mybatis忽略了超类上的属性(setter也在超类上)

代码如下:

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(){...}

}
公共类CocTreeNode扩展CocBean实现TreeNode{
私有字符串level1、level2;
公共void setLevel1(字符串level1){…}
公共void setLevel2(字符串level2){…}
公共字符串getLevel1(){…}
公共字符串getLevel1(){…}
}
公共类椰子豆{
受保护的字符串名称;
保护双卷;
公共无效集合名(字符串名){…}
公共void setVolume(双卷){…}
公共字符串getName(){…}
公共双getVolume(){…}
}
我的结果图是-

<resultMap id="simpleRow" type="CocTreeNode">
  <id property="level1" column="LEVEL1"/>
  <id property="level2" column="LEVEL2"/>
  <result property="name" column="NAME"/>
  <result property="volume" column="VOLUME"/>
</resultMap>

生成的CocTreeNode对象填充有“level1”和“level2”属性,但不填充“name”和“volume”

我尝试过使用extends,但没有任何区别

任何想法都将不胜感激。

您必须在simpleRow resultmap中使用extends来扩展CocBean resultmap的属性:

<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>


您确定sql语句工作正常吗?是的。将CocBean(超类)的代码复制到CocTreeNode中可以正确设置所有属性。我很高兴您发现我的答案很有帮助。你应该接受。我的要求已经改变了,我把超类抽象化了。Extends属性现在似乎不起作用。如果您只是将super类更改为asbtract,它肯定会起作用。在这里发布这些bean和两个结果图。