Mybatis多对多

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <!DOCTYPE mapper  
  4.         PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"  
  5.         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">  
  6.   
  7. <mapper namespace="cn.hello.dao.ITeacher">  
  8.   
  9.     <resultMap id="teacherMappers" type="Teacher">  
  10.         <id column="tid" property="tid"></id>  
  11.         <result column="tname" property="tname"></result>  
  12.         <collection property="stus" ofType="Student">  
  13.             <id column="sid" property="sid"></id>  
  14.             <result column="sname" property="sname"></result>  
  15.         </collection>  
  16.     </resultMap>  
  17.   
  18. <select id="getTeacher" resultMap="teacherMappers">  
  19.     SELECT t.tid,t.tname,s.sid,s.sname  
  20.   
  21.   FROM teacher t,student  s ,teacher_student   ts  
  22.   WHERE  t.tid=ts.tid  
  23.   and  s.sid=ts.sid  
  24.    and   t.tid=#{tid}  
  25.   
  26. </select>  
  27. </mapper>  
[html]  view plain  copy
  1. @Test  
  2.     public  void a(){  
  3.         SqlSession session = MyBatisUtil01.getSession();  
  4.         ICategory mapper = session.getMapper(ICategory.class);  
  5.         List<Category> list = mapper.getChildreByPid(1);  
  6.         for (Category item :list  
  7.              ) {  
  8.             System.out.println(item);  
  9.         }  
  10.   
  11.     }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值