81,122
社区成员




<resultMap id="clazzResultMap" type="org.fkit.domain.Clazz">
<id property="id" column="id" />
<result property="code" column="code"/>
<!-- 班级的学生属性,因为一个班级有多个学生,所以该属性是一个集合 -->
<collection property="students" javaType="ArrayList"
column="id" ofType="org.fkit.domain.Student"
select="selectStudentWithId"/>
</resultMap>
<!-- 映射学生对象的resultMap -->
<resultMap id="studentResultMap" type="org.fkit.domain.Student">
<id property="id" column="id" />
<result property="name" column="name"/>
<result property="sex" column="sex"/>
<result property="age" column="age"/>
<!-- 关联映射 -->
<association property="clazz" column="clazz_id"
javaType="org.fkit.domain.Clazz"
select="selectClazzWithId"/>
</resultMap>
<!-- 根据班级id查询班级 -->
<select id="selectClazzWithId" resultType="org.fkit.domain.Clazz">
SELECT * FROM TB_CLAZZ where id = #{id}
</select>
<!-- 查询所有学生信息 -->
<select id="selectStudent" resultMap="studentResultMap">
SELECT * FROM TB_STUDENT
</select>
<!-- 根据班级id查询学生 -->
<select id="selectStudentWithId" resultType="org.fkit.domain.Student">
SELECT * FROM TB_STUDENT where clazz_id = #{id}
</select>
<!-- 查询所有班级信息 -->
<select id="selectClazz" resultMap="clazzResultMap">
SELECT * FROM TB_CLAZZ
</select>