码迷,mamicode.com
首页 > 其他好文 > 详细

mybatis 脚本

时间:2018-07-30 20:15:25      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:怎么   list   lis   fail   select   tty   imp   from   属性   

1,批量更新

 注意:当 parameterType="java.util.List"  的时候,collection="list" 

<update id="resultFeedback" parameterType="java.util.List">
    UPDATE tm_esim_social_result 
       SET result_status = 
             <foreach collection="list" item="item" separator=" " open="(CASE id" close="ELSE result_status END),">
                WHEN #{item.id,jdbcType=VARCHAR} THEN #{item.resultStatus,jdbcType=VARCHAR}
             </foreach>
           fail_reason = 
             <foreach collection="list" item="item" separator=" " open="(CASE id" close="ELSE fail_reason END),">
                WHEN #{item.id,jdbcType=VARCHAR} THEN #{item.failReason,jdbcType=VARCHAR}
             </foreach>
           state = 
             <foreach collection="list" item="item" separator=" " open="(CASE id" close="ELSE state END),">
                WHEN #{item.id,jdbcType=VARCHAR} THEN #{item.state,jdbcType=VARCHAR}
             </foreach>
           feedback_time = NOW(),
           update_by = #{item.updateBy,jdbcType=VARCHAR},
           update_date = NOW()
     WHERE id IN 
         <foreach collection="list" item="item" separator="," open="(" close=")">
            #{item.id,jdbcType=VARCHAR}
         </foreach>
</update>

 当parameterType为一个对象的时候,注意,foreach 的 colletion 属性为这个对象下面的属性

<update id="feedbackAll" parameterType="com.sf.esim.domain.payable.payDo">             
    UPDATE table01
       SET state = #{state,jdbcType=VARCHAR}                                                        
     WHERE id IN                                                                      
    <foreach collection="transferIdList" index="index" item="item" open="(" separator="," close=")">
          #{item,jdbcType=VARCHAR}                                                                  
    </foreach>                                                                                      
</update>                                                                                           

 批量增加:

<insert id="addListPayable" parameterType="com.sf.haha.domain.payable.PayableDo">
    INSERT INTO tm_esim_payable 
    ( 
      tm_esim_payable_id,
      pay_the_city,
      account,
      bussi_type
     )
    VALUES 
    <foreach collection="list" item="item" separator=",">  
     (
       #{item.tmEsimPayableId},
       #{item.payTheCity},
       #{item.account},
       #{item.bussiType}
       )
    </foreach>  
</insert>

 这个我还没有测试过,懒得测试,因为其实大概知道怎么着就可以的了

<update id="updatePersonalUnitPayById" parameterType="com.sf.esim.domain.deducted.DeductingDetailDo">
        <foreach collection="list" index="index" item="item">
            update tm_esim_deducting_detail
            <set>
                personal_pay_edit = #{item.personalPayEdit}
                ,unit_pay_edit =#{item.unitPayEdit}
                ,edit_declare = #{item.editDeclare}
            </set>
            where deducting_detail_id = #{item.deductingDetailId};
        </foreach>
    </update>

如果list的泛型是string,则collection为list

    <select id="getOrgName" parameterType="java.util.List" resultType="java.lang.String">
        SELECT GROUP_CONCAT(ORG_NAME) FROM zthr_etl_hr_org_business WHERE ORG_ID IN
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
                #{item,jdbcType=VARCHAR}     
           </foreach> 
    </select>

 

END

mybatis 脚本

标签:怎么   list   lis   fail   select   tty   imp   from   属性   

原文地址:https://www.cnblogs.com/ericguoxiaofeng/p/8920844.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!