Mybatis多表关联及批量插入

 <resultMap type ="Customer" id= "customerMap">
             <id property ="id" column="id" />
             <result property ="name" column="name" />
             <result property ="age" column="age" />
             <result property ="address" column="address" />
            
             <collection property ="orders" ofType="Order" >
                   <id property ="orderId" column="oid" />
                   <result property ="orderPrice" column="price" />
                   <result property ="orderNumber" column="orderNumber" />
             </collection>
       </resultMap>
      
       <select id ="selectCustomerById" parameterType="string" resultMap="customerMap" >
            select c.id,c.name,c.age,c.address,o.id oid,o.price,o.orderNumber,o.cid from customer c,orders o where c.id=o.cid and c.id=#{id}
       </select>
      
       <!-- 批量插入数据 -->
       <insert id ="insertBatch" parameterType="list" >
            insert into customer(id,name,age,address) values
             <foreach collection ="list" item="obj" separator="," >
                  (#{obj.id},#{obj.name},#{obj.age},#{obj.address})
             </foreach>
       </insert>

  

posted @ 2017-06-26 22:34  judy999  阅读(9497)  评论(0编辑  收藏  举报