`

mybaits级联查询

 
阅读更多
mybaits级联查询

1对1的级联或关联查询如下:用association,配置好对应的select子查询就行。
<resultMap id="usersResult" type="com.zlwh.member.model.Users">
        <result property="id" column="id"/>
        <result property="loginName" column="login_name"/>   
        <result property="schoolId" column="school_id"/> 
          <!-- 1对1查询用户学校--> 
        <association column="school_id" property="school"
        javaType="com.zlwh.member.model.School" select="getSchoolById" />
</resultMap>

<resultMap id="schoolResult" type="com.zlwh.member.model.School">
        <result property="id" column="id"/>
        <result property="schoolName" column="school_name"/>
        <result property="schoolCode" column="school_code"/>
</resultMap>
   
    <select id="getSchoolById" resultMap="schoolResult">
SELECT * FROM school WHERE id = #{id}
</select>

1对多的时候用collection,配置略
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics