<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--namespace 命名空间-->
<mapper namespace="com.sf.mapper.ManyToManyMapper">
    <resultMap id="ManyToMany" type="student">
        <id column="sid" property="id"/>
        <result column="sname" property="name"/>
        <result column="age" property="age"/>
        <collection property="courses" ofType="course">
            <id column="cid" property="id"/>
            <result column="cname" property="name"/>
        </collection>
    </resultMap>

    <select id="selectAll" resultMap="ManyToMany">

        SELECT s.id sid,s.name sname,s.age,c.id cid,c.name cname
        FROM student s,course c,stu_cr sc
        WHERE s.id=sc.sid AND c.id=sc.cid

    </select>
</mapper>