zoukankan      html  css  js  c++  java
  • MyBatis常用批量方法

    <!-- 批量添加派车单子表数据 -->
    	  <insert id="addBatch" parameterType="java.util.List" >
    			insert into hylm_shipment_item
    			(
    				ship_number,
    				order_number,
    				pre_number,
    				goods_id,
    				real_num,
    				real_weight,
    				real_cubage,
    				cost,
    				creater,
    				createDate,
    				finalOperator,
    				operatTime,
    				pId,
    				uId,
    				orgId,
    				roleId
    			)
    			values
    			<foreach collection="list" item="item" index="index" separator=",">
    				 (
    					 #{item.shipnumber,jdbcType=VARCHAR},
    					 #{item.ordernumber,jdbcType=VARCHAR},
    					 #{item.prenumber,jdbcType=VARCHAR},
    					 #{item.goodsid,jdbcType=FLOAT},
    					 #{item.realnum,jdbcType=VARCHAR},
    					 #{item.realweight,jdbcType=VARCHAR},
    					 #{item.realcubage,jdbcType=VARCHAR},
    					 #{item.cost,jdbcType=VARCHAR},
    					 #{item.creater,jdbcType=VARCHAR},
    					 #{item.createDate,jdbcType=VARCHAR},
    					 #{item.finalOperator,jdbcType=VARCHAR},
    					 #{item.operatTime,jdbcType=VARCHAR},
    					 #{item.pId,jdbcType=VARCHAR},
    					 #{item.uId,jdbcType=VARCHAR},
    					 #{item.orgId,jdbcType=VARCHAR},
    					 #{item.roleId,jdbcType=VARCHAR}
    				 )
    			</foreach>
    	  </insert>
    	  
    	  <!-- 批量删除中转地数据 -->
    	  <delete id = "deleteBatch" parameterType = "java.util.List">  
    		    <![CDATA[  
    		       delete from hylm_shipment_item where id in  
    		    ]]>  
    		    <foreach collection="list" item="model" open="(" separator="," close=")">
    		    	#{model.id}  
    		    </foreach>  
    	  </delete> 
    	  
    	  <!-- 批量更新派车单子表数据 -->
    	  <update id="updateBatch" parameterType="java.util.List">
    			<foreach collection="list" item="item" index="index" separator=";">
    				update hylm_shipment_item  
    	             <trim prefix="set" prefixOverrides=","> 
    					<if test="item.id != null and item.id != ''">
    					    ,id = #{item.id}
    					</if>
    					<if test="item.shipnumber != null and item.shipnumber != ''">
    					    ,ship_number = #{item.shipnumber}
    					</if>
    					<if test="item.ordernumber != null and item.ordernumber != ''">
    					    ,order_number = #{item.ordernumber}
    					</if>
    					<if test="item.prenumber != null and item.prenumber != ''">
    					    ,pre_number = #{item.prenumber}
    					</if>
    					<if test="item.goodsid != null and item.goodsid != ''">
    					    ,goods_id = #{item.goodsid}
    					</if>
    					<if test="item.realnum != null and item.realnum != ''">
    					    ,real_num = #{item.realnum}
    					</if>
    					<if test="item.realweight != null and item.realweight != ''">
    					    ,real_weight = #{item.realweight}
    					</if>
    					<if test="item.realcubage != null and item.realcubage != ''">
    					    ,real_cubage = #{item.realcubage}
    					</if>
    					<if test="item.cost != null and item.cost != ''">
    					    ,cost = #{item.cost}
    					</if>
    					<if test="item.creater != null and item.creater != ''">
    					    ,creater = #{item.creater}
    					</if>
    					<if test="item.createDate != null and item.createDate != ''">
    					    ,createDate = #{item.createDate}
    					</if>
    					<if test="item.finalOperator != null and item.finalOperator != ''">
    					    ,finalOperator = #{item.finalOperator}
    					</if>
    					<if test="item.operatTime != null and item.operatTime != ''">
    					    ,operatTime = #{item.operatTime}
    					</if>
    					<if test="item.pId != null">
                           ,pId = #{item.pId,jdbcType=VARCHAR}
                       </if>
                       <if test="item.uId != null">
                           ,uId = #{item.uId,jdbcType=VARCHAR}
                       </if>
                       <if test="item.orgId != null">
                           ,orgId = #{item.orgId,jdbcType=VARCHAR}
                       </if>
                       <if test="item.roleId != null">
                           ,roleId = #{item.roleId,jdbcType=VARCHAR}
                       </if>
    				</trim>
    	             where 1 = 1
    	             <if test="item.id != null and item.id != ''">
    					    and id = #{item.id}
    					</if>
    					<if test="item.ordernumber != null and item.ordernumber != ''">
    					    and order_number = #{item.ordernumber}
    					</if>
    					<if test="item.uId != null and item.uId != ''">
    					    and uId = #{item.uId}
    					</if>
    			</foreach>
    	  </update>
    
  • 相关阅读:
    student
    super
    java 浮点数
    视图
    日期转换函数
    左外连接,右外连接,全外连接,自然连接,自连接区别
    Python中sys.argv[ ]的用法
    0 Scala
    统计字符串字符个数
    3个链表排序整合到一起
  • 原文地址:https://www.cnblogs.com/deepbreath/p/5015112.html
Copyright © 2011-2022 走看看