正文

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

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

分享到:

iBATIS的多对多映射配置6,sqlmap配置文件

Teacher.xml

  1. ﹤?xml version="1.0" encoding="UTF-8" ?﹥  
  2. !DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"     
  3.    "http://ibatis.apache.org/dtd/sql-map-2.dtd"﹥  
  4.      
  5.    ﹤sqlMap namespace="teacher"﹥  
  6.        ﹤typeAlias alias="Teacher" type="com.lsm.domain.Teacher" /﹥  
  7.  ﹤typeAlias alias="Student" type="com.lsm.domain.Student" /﹥  
  8.    
  9.  ﹤resultMap class="Teacher" id="teacherBasicResultMap"﹥  
  10.   ﹤result property="id" column="id"/﹥  
  11.   ﹤result property="name" column="name"/﹥  
  12.   ﹤result property="subject" column="subject"/﹥  
  13.  ﹤/resultMap﹥  
  14.  ﹤!-- 下面这个resultMap中有个students属性,这个结果映射继承自上面的结果映射  
  15.   由于有了继承,结果映射可以任意扩展--﹥  
  16.  ﹤resultMap class="Teacher" id="teacherWithTeacherResultMap" extends="teacherBasicResultMap"﹥  
  17.   ﹤result property="students" column="id" select="getStudentsByTeacherId"/﹥  
  18.  ﹤/resultMap﹥  
  19.  ﹤!-- 这个查询中使用到了上面定义的结果映射,从而决定了查询出来的Teacher中关联出相关的students,在student.xml中配置相似,不再注释。--﹥  
  20.  ﹤select id="getTeachers" resultMap="teacherWithTeacherResultMap"﹥  
  21.   ﹤!--[CDATA[  
  22.    select * from teacher  
  23.   ]]﹥  
  24.  ﹤/select﹥  
  25.    
  26.  ﹤select id="getStudentsByTeacherId" resultClass="Student"﹥  
  27.   ﹤![CDATA[   
  28.    select s.* from student s,student_teacher st where s.id=st.studentid and st.teacherid=#value#   ]]--﹥  
  29.  ﹤/select﹥  
  30.          
  31.    ﹤/sqlMap﹥  
  32.  
  33. tudent.xml  
  34.  
  35. ﹤?xml version="1.0" encoding="UTF-8" ?﹥  
  36. !DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"     
  37.    "http://ibatis.apache.org/dtd/sql-map-2.dtd"﹥  
  38.      
  39.    ﹤sqlMap namespace="student"﹥  
  40.        ﹤typeAlias alias="Student" type="com.lsm.domain.Student" /﹥  
  41.  ﹤typeAlias alias="Teacher" type="com.lsm.domain.Teacher" /﹥  
  42.    
  43.  ﹤resultMap class="Student" id="studentBasicResultMap"﹥  
  44.   ﹤result property="id" column="id"/﹥  
  45.   ﹤result property="name" column="name"/﹥  
  46.   ﹤result property="birthday" column="birthday"/﹥  
  47.  ﹤/resultMap﹥  
  48.    
  49.  ﹤resultMap class="Student" id="studentWithTeacherResultMap" extends="studentBasicResultMap"﹥  
  50.   ﹤result property="teachers" column="id" select="getTeachersByStudentId"/﹥  
  51.  ﹤/resultMap﹥  
  52.    
  53.  ﹤select id="getStudents" resultMap="studentWithTeacherResultMap"﹥  
  54.   ﹤!--[CDATA[  
  55.    select * from student  
  56.   ]]﹥  
  57.  ﹤/select﹥  
  58.    
  59.  ﹤select id="getTeachersByStudentId" resultClass="Teacher"﹥  
  60.   ﹤![CDATA[   
  61.    select t.* from teacher t,student_teacher st where t.id=st.teacherid and st.studentid=#value#   ]]--﹥  
  62.  ﹤/select﹥  
  63.          
  64.    ﹤/sqlMap﹥ 


阅读(2500) | 评论(1)


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

评论

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