<!-- 多对一-->
<resultMap id="cc1" type="classInfo">
<result property="classId" column="classId"></result>
<result property="className" column="className"></result>
<collection property="studentInfo" ofType="studentInfo">
<result property="stuId" column="stuId"></result>
<result property="stuName" column="stuName"></result>
<result property="stuSex" column="stuSex"></result>
<result property= "stuAge" column="stuAge"></result>
<result property="stuPassword" column="stuPassword"></result>
</collection>
</resultMap>
<select id="findClassInfoByClassId" resultMap="cc1">
select s.*,c.* from studentinfo s,classinfo c where s.classId_stuId = c.classId and c.classId = #{classId}
</select>
Mybatis多对一
这个博客内容展示了如何在MyBatis中配置和使用多对一映射,通过resultMap定义了classInfo类及其包含的studentInfo集合,查询语句用于根据班级ID获取班级及对应学生信息的完整数据。
摘要由CSDN通过智能技术生成