<?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">
<mapper namespace="com.java1234.mappers.GradeMapper">
<resultMap type="Grade" id="GradeResult">
<id property="id" column="id"/>
<result property="gradeName" column="gradeName"/>
<!-- 其中column="id"为grade表的主键id -->>
<collection property="students" column="id" select="com.java1234.mappers.StudentMapper.findByGradeId"/>
</resultMap>
<select id="findById" parameterType="Integer" resultMap="GradeResult">
select * from t_grade where id=#{id}
</select>
</mapper>
使用collectionsh属性
具体代码:https://download.youkuaiyun.com/download/chpllp/10587993