其他分享
首页 > 其他分享> > Mybatis多对一查询处理

Mybatis多对一查询处理

作者:互联网

1、子查询

	<select id="getStudent" resultMap="StudentTeacher">
        select * from mybatis.student
    </select>

    <resultMap id="StudentTeacher" type="Student">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <association property="teacher" column="tid" javaType="Teacher" select="getTeacher"/>
    </resultMap>

    <select id="getTeacher" resultType="com.wjj.pojo.Teacher">
        select * from mybatis.teacher where id = #{id}
    </select>

2、联表查询

    <resultMap id="StudentTeacher2" type="Student">
        <result property="id" column="sid"/>
        <result property="name" column="sname"/>
        <association property="teacher" javaType="Teacher">
            <result property="id" column="tid"/>
            <result property="name" column="tname"/>
        </association>
    </resultMap>

标签:查询处理,查询,mybatis,联表,Mybatis,id,select
来源: https://blog.csdn.net/qq_42472710/article/details/112402152