<association>关联的结果查询

association:用于对象间包含关系映射

<mapper namespace="org.apache.ibatis.submitted.associationtest.Mapper">  
    <resultMap type="org.apache.ibatis.submitted.associationtest.Car" id="carResult">  
        <id column="carid" property="id"/>  
        <result column="cartype" property="type"/>  
        <association property="engine" resultMap="engineResult"/>  
        <association property="brakes" resultMap="brakesResult"/>  
    </resultMap>  
    <resultMap type="org.apache.ibatis.submitted.associationtest.Engine" id="engineResult">  
        <result column="enginetype" property="type"/>  
        <result column="enginecylinders" property="cylinders"/>  
    </resultMap>  
    <resultMap type="org.apache.ibatis.submitted.associationtest.Brakes" id="brakesResult">  
        <result column="brakesType" property="type"/>  
    </resultMap>  
    <select id="getCars" resultMap="carResult">  
        select * from cars  
    </select>  
    <select id="getCarsNonUnique" resultMap="carResult">  
        select 1 as carid, cartype, enginetype, enginecylinders, brakestype from cars  
    </select>  
    <select id="getCars2" resultMap="carResult">  
        select 1 as carid, cartype, enginetype, enginecylinders, brakestype from cars where carid in (1,2)  
    </select>  
</mapper>  

猜你喜欢

转载自www.cnblogs.com/yifanSJ/p/9094025.html