要点:
多对一:查询的多个对象中有一个属性包含一个复杂对象,使用association标签嵌套
一对多:查询的单个对象中的一个属性包含多个其他对象,使用collection标签嵌套
javaType为实体类中属性的类型,为常用基本数据类型时可以省略
ofType则是用来指定到List或集合中的实体类类型,泛型中的约束类型
按照查询嵌套时,即查询出来后再嵌套,查询语句一般是由两个查询语句组成,类似子查询
按照结果嵌套时,即查询时整体嵌套,查询语句一般为联合查询
注意:以下实体类都已使用了别名
1.多对一:使用association //查询所有学生以及对应老师的信息
List selectAllStu2();
List selectAllStu3();
按照查询嵌套:子查询
按照结果嵌套:联合查询
select s.id sid,s.name sname,t.name tname,t.id tid from student s,teacher t where s.tid = t.id
2.一对多:使用collection
Teacher selectTeacher(@Param("tid") int id);//查询一个老师的多个学生
Teacher selectTeacher2(@Param("tid") int id);
按照查询嵌套:子查询
select * from teacher where id=#{tid};
select * from student where tid=#{tid};
按照结果嵌套:联合查询
select t.id tid,t.name tname,s.id sid,s.name sname from student s,teacher t where t.id=s.tid and t.id=#{tid};



