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>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM