ClassesMapper.xml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<id property= "id" column= "c_id" javaType= "int" /> <result property= "name" column= "c_name" javaType= "String" /> <!-- <association property= "teacher" javaType= "Teacher" > <id property= "id" column= "t_id" javaType= "int" /> <result property= "name" column= "t_name" javaType= "String" /> <result property= "age" column= "t_age" javaType= "int" /> </association> --> <association property= "teacher" javaType= "Teacher" resultMap= "com.lsj.test.mybatis.mapper.TeacherMapper.teacherMap" ></association> <collection property= "studentList" ofType= "Student" resultMap= "com.lsj.test.mybatis.mapper.StudentMapper.studentMap" ></collection> </resultMap> <sql id= "selectAllClassesSql" > SELECT c.id as c_id,c.name as c_name,teacher_id, t.id as t_id,t.name as t_name,t.age as t_age, s.id as stu_id,s.name as stu_name,s.classes_id from classes c,teacher t,student s </sql> |
TeacherMapper.xml的resultMap:
1
2
3
4
5
|
<resultMap type= "Teacher" id= "teacherMap" > <id property= "id" column= "t_id" javaType= "int" /> <result property= "name" column= "t_name" javaType= "String" /> <result property= "age" column= "t_age" javaType= "int" /> </resultMap> |
利用命名空間+resultMapID就可以直接引用其他Mapper文件的resultMap,其中resultMap的column在本文件中也有用,也可以對(duì)應(yīng)sql語句中的column別名。
總結(jié)
以上所述是小編給大家介紹的mybatis 不同Mapper文件引用resultMap,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留
言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)服務(wù)器之家網(wǎng)站的支持!
原文鏈接:http://blog.csdn.net/caser_hdmi/article/details/76064542