江苏建设外贸公司网站,做类似电影天堂的网站违法吗,最新软件推广,wordpress查询分类为空–查询所有学生所在班级的信息#xff08;一对一#xff09; –班级查询学生的操作#xff08;一对多#xff09; –遇到的问题#xff1a; 查询的SQL语句非常的简单#xff0c;但是如何把查询的数据接受这个就是一个问题 [1]把每一个实体中的字段拿出来组建成一个新的实…–查询所有学生所在班级的信息一对一 –班级查询学生的操作一对多 –遇到的问题 查询的SQL语句非常的简单但是如何把查询的数据接受这个就是一个问题 [1]把每一个实体中的字段拿出来组建成一个新的实体 返回还是resultType 存在的问题映射的内容会出现重复的字段 [2] resultMap:映射的操作 接口 StudentMapper.java
public interface StudentMapper {//多表查询操作ListStudent selectAll2();
}ClazzMapper.java
public interface ClazzMapper {//多表查询班级学生信息ListClazz selectAll2();
}XML StudentMapper.xml select idselectAll2 resultMaprm2SELECT * FROM student s JOIN clazz c ON s.clazznoc.clazzno/selectresultMap idrm2 typestudent!--注意书写的每一个值就是接受数据库查询的数据所以想要接受的数据的字段不可以省去--id columnsid propertysid/idresult columnsname propertysname/resultresult columnclazzno propertyclazzno/resultassociation propertycla javaTypeclazz //‘cla’student表中的clazz对象id columnclazzno propertyclazzno/idresult columncname propertycname/result/association/resultMapClazzmapper.xml select idselectAll2 resultMaprm2SELECT * FROM student s JOIN clazz c ON s.clazznoc.clazzno/selectresultMap idrm2 typeclazzid columnclazzno propertyclazzno/idresult columncname propertycname/resultcollection propertyli ofTypestudent //‘li’ clazz表中的学生集合 id columnsid propertysid/idresult columnsname propertysname/resultresult columnclazzno propertyclazzno/result/collection/resultMap测试 //[4]执行方法StudentMapper stuMapper sqlSession.getMapper(StudentMapper.class);ClazzMapper claMapper sqlSession.getMapper(ClazzMapper.class);//查询所有学生所在的班级的信息/*ListStudent list stuMapper.selectAll2();for(Student student:list){System.out.println(student);}*/ListClazz list claMapper.selectAll2();for(Clazz clazz:list){System.out.println(clazz);}4、Auto_Mapping 数据注入的方式 [1]自动注入方式 Auto_Mapping (自己封装的实体属性和数据库的字段是一样的情况Mybatis会自动的注入) [2]手动注入的方式 resultMap 作用解决自己做的实体的封装和数据库的字段不一致的问题 5、resultType和resultMap使用场景 [1]如果你做的是单表的查询并且封装的实体和数据库的字段一一对应 resultType [2]如果实体封装的属性和数据库的字段不一致 resultMap [3]使用的是多表的联合查询 resultMap [4]使用N1查询的时候 resultMap