一对多查询
//嵌套查询
<resultMap id="specialListID2" type="com.pojo.Special"> <id property="specialId" column="specialId"/> <result property="specialName" column="specialName"/> <result property="specialUrl" column="specialUrl"/> <collection property="specialCourseList" column="{specialId=specialId}" select="selectSpecialCourseList" ofType="com.pojo.SpecialCourse"/> </resultMap> <select id="selectSpecialCourseList" resultType="com.pojo.SpecialCourse"> select * from specialcourse where specialId = #{specialId} </select> <select id="selectMapList" parameterType="map" resultMap="specialListID2"> select * from special s </select>
//结果嵌套
<resultMap id="specialListID" type="com.pojo.Special"> <id property="specialId" column="specialId"/> <result property="specialName" column="specialName"/> <result property="specialUrl" column="specialUrl"/> <collection property="specialCourseList" ofType="com.pojo.SpecialCourse"> <id property="specialCourseId" column="specialCourseId"/> <result property="specialId" column="specialId"/> <result property="courseInfoId" column="courseInfoId"/> <result property="sort" column="sort"/> </collection> </resultMap> <select id="selectMapList" parameterType="map" resultMap="specialListID2"> select * from special s left join specialcourse sc on sc.specialId = s.specialId </select>