2012-12-06 71 views
5

我有两个类,其中一个继承另一个。我想我的映射结果的子类,MyBatis的被忽略的超(二传手也对超类)的属性Mybatis - 未映射的继承属性

守则如下:

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

} 

我resultMap的是 -

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

我试过使用延伸,但没有任何区别。

任何想法将不胜感激。

+0

你确定,你的sql语句正常工作? – boskonovic

+0

是的。将CocBean(超类)的代码复制到CocTreeNode中会导致正确设置所有属性。 –

回答

9

你必须使用在simpleRow结果映射来从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> 
+0

就是这样。谢谢! –

+0

我很高兴你找到我的答案有帮助。那么你应该接受它。 – Behnil

+0

我的要求已经改变,我做了超类抽象。现在扩展属性似乎不起作用。 –