简体   繁体   中英

Ibatis filling up Nested object in Java

I have one java class which resembles to

class A{
String a;
B bclass;
}

class B{
String b;
String c;
}

my ibatis query is: Select a,b,c from A_TABLE and resultmap I want is something like this where I can fill properties of class B (Bb,Bc) as well.

<resultMap class="A" id="resmap">
<result property="a"  column="A"  jdbcType="VARCHAR"/>
<result property="bclass.b"  column="B"  jdbcType="VARCHAR"/>
<result property="bclass.c"  column="C"  jdbcType="VARCHAR"/>
</resultmap>

any idea how I can fill this object A from ibatis query so I have all 3 a,b,c properties filled?

The mapping of inner objects is made with association tag. You need something like this:

<resultMap id="resmap" type="A">
    <result property="a" column="a"/>
    <association property="b" javaType="B">
        <result property="b" column="b_b"/>
        <result property="c" column="b_c"/>
    </association>
</resultMap>

Check documentation as well, it's explained in details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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