说说Mybatis中的Collection标签元素

以下是一个典型的主子表应用,例如:
一个入库单,有入库单头(主表:'单号','日期'等信息)及入库单物料明细(子表:'物料编号','物料名称'等信息)两张表构成,在用mybatis来处理时,子表的数据就要用到Collection层现(Collection集合顾名思议就是可以放很多条记录的一个容器)
<resultMap type="Bill" id="ResultBill">
	       <id property="id" column="id"/>
	       <result property="dh" column="dh"  />	      
	       <result property="rq" column="rq"/>
	       <association property="author"  javaType="Author"  >
	          <id  property="id"  column="idAutor" />
	          <result property="name" column="authorName" />
	          <result property="email" column="authorEmail"/>
	       </association>	       
	       <collection property="det1"  javaType="ArrayList" ofType="BillDet1" >
	          <id property="id" column="idDet1"/>
	          <result property="dh" column="dhDet1"/>
	          <result property="wlbm" column="wlbm"/>
	          <result property="wlmc" column="wlmc"/>
	          <result property="unit" column="unit"/>
	          <result property="qty" column="qty"/>
	       </collection>
</resultMap>
   <select id="getAllBill" resultMap="ResultBill">
        select t1.id,t1.dh,t1.idAuthor,t1.rq
       ,t2.name as authorName ,t2.email as authorEmail
       ,t3.dh as dhDet1,t3.id as idDet1,t3.wlbm as wlbm,t3.wlmc as wlmc,t3.unit as unit,t3.qty as qty  
   from  Bill_Det1   t3
   left outer join  bill  t1 on  t1.dh=t3.dh    
   left outer join Author   t2  on t1.idAuthor=t2.idAuthor
 </select>

在collection中发现有个column属性,在以上Demo中无需使用,经测试发现,此column属性,一般与select属性结合使用,但网上很多资料中并未作出说明,故在此说明一下,让后来者少走弯路.

如:

 <collection property="det1"  javaType="ArrayList" ofType="BillDet1" column="dh" select="getAllBillDet1">
	          <id property="id" column="idDet1"/>
	          <result property="dh" column="dhDet1"/>
	          <result property="wlbm" column="wlbm"/>
	          <result property="wlmc" column="wlmc"/>
	          <result property="unit" column="unit"/>
	          <result property="qty" column="qty"/>
</collection>
  <select id="getAllBillDet1" resultMap="ResultBillDet1">
       select 
          t3.dh as dhDet1,t3.id as idDet1,t3.wlbm as wlbm,t3.wlmc as wlmc,t3.unit as unit,t3.qty as qty  
    	 from    Bill_Det1 t3          
</select>
以上使用时应注意的一些小细节,特此记录,备查.
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值