首页 > 代码库 > mybatis处理一对多的查询

mybatis处理一对多的查询

//查询出某个班级对应的所有老师和学生

1、使用嵌套结果

select * from classes c,teacher t,student s where c.teacher_id = t.t_id and c.c_id = s.class_id where c_id = #{id}

2、使用嵌套查询

select * from classes where c_id = #{id};

select * form teacher where t_id = #{id}

select * from student where class_id = #{id}

 

mybatis处理一对多的查询