正文

iBATIS的多对多映射配置方法之二(转)2012-09-19 15:05:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/lovebugs/53815.html

分享到:

iBATIS的多对多映射配置6,sqlmap配置文件 Teacher.xml ﹤?xml version="1.0" encoding="UTF-8" ?﹥   !DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"         "http://ibatis.apache.org/dtd/sql-map-2.dtd"﹥            ﹤sqlMap namespace="teacher"﹥          ﹤typeAlias alias="Teacher" type="com.lsm.domain.Teacher" /﹥    ﹤typeAlias alias="Student" type="com.lsm.domain.Student" /﹥        ﹤resultMap class="Teacher" id="teacherBasicResultMap"﹥     ﹤result property="id" column="id"/﹥     ﹤result property="name" column="name"/﹥     ﹤result property="subject" column="subject"/﹥    ﹤/resultMap﹥    ﹤!-- 下面这个resultMap中有个students属性,这个结果映射继承自上面的结果映射     由于有了继承,结果映射可以任意扩展--﹥    ﹤resultMap class="Teacher" id="teacherWithTeacherResultMap" extends="teacherBasicResultMap"﹥     ﹤result property="students" column="id" select="getStudentsByTeacherId"/﹥    ﹤/resultMap﹥    ﹤!-- 这个查询中使用到了上面定义的结果映射,从而决定了查询出来的Teacher中关联出相关的students,在student.xml中配置相似,不再注释。--﹥    ﹤select id="getTeachers" resultMap="teacherWithTeacherResultMap"﹥     ﹤!--[CDATA[      select * from teacher     ]]﹥    ﹤/select﹥        ﹤select id="getStudentsByTeacherId" resultClass="Student"﹥     ﹤![CDATA[       select s.* from student s,student_teacher st where s.id=st.studentid and st.teacherid=#value#   ]]--﹥    ﹤/select﹥                ﹤/sqlMap﹥     tudent.xml     ﹤?xml version="1.0" encoding="UTF-8" ?﹥   !DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"         "http://ibatis.apache.org/dtd/sql-map-2.dtd"﹥            ﹤sqlMap namespace="student"﹥          ﹤typeAlias alias="Student" type="com.lsm.domain.Student" /﹥    ﹤typeAlias alias="Teacher" type="com.lsm.domain.Teacher" /﹥        ﹤resultMap class="Student" id="studentBasicResultMap"﹥     ﹤result property="id" column="id"/﹥     ﹤result property="name" column="name"/﹥     ﹤result property="birthday" column="birthday"/﹥    ﹤/resultMap﹥        ﹤resultMap class="Student" id="studentWithTeacherResultMap" extends="studentBasicResultMap"﹥     ﹤result property="teachers" column="id" select="getTeachersByStudentId"/﹥    ﹤/resultMap﹥        ﹤select id="getStudents" resultMap="studentWithTeacherResultMap"﹥     ﹤!--[CDATA[      select * from student     ]]﹥    ﹤/select﹥        ﹤select id="getTeachersByStudentId" resultClass="Teacher"﹥     ﹤![CDATA[       select t.* from teacher t,student_teacher st where t.id=st.teacherid and st.studentid=#value#   ]]--﹥    ﹤/select﹥                ﹤/sqlMap﹥ 

阅读(3640) | 评论(1)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册