mybatis批量查询,新增,修改,删除

批量修改

 <update id="updateBatch" parameterType="java.util.List">
        update membership_card
        <trim prefix="set" suffixOverrides=",">
            <!-- 拼接case when 这是一种写法 -->
            <!--<foreach collection="list" separator="" item="cus" open="c_age = case id" close="end, ">-->
            <!--when #{cus.id} then #{cus.age}-->
            <!--</foreach>-->

            <!-- 拼接case when 这是另一种写法,这种写着更专业的感觉 -->
            <trim prefix="card_use_number =case" suffix="end,">
                <foreach collection="list" item="cus">
                    <if test="cus.cardUseNumber!=null">
                        when id=#{cus.id} then #{cus.cardUseNumber}
                    </if>
                </foreach>
            </trim>
            <trim prefix="card_balance =case" suffix="end,">
                <foreach collection="list" item="cus">
                    <if test="cus.cardBalance!=null">
                        when id=#{cus.id} then #{cus.cardBalance}
                    </if>
                </foreach>
            </trim>
            <trim prefix="card_level =case" suffix="end,">
                <foreach collection="list" item="cus">
                    <if test="cus.cardLevel!=null">
                        when id=#{cus.id} then #{cus.cardLevel}
                    </if>
                </foreach>
            </trim>
            <trim prefix="sell_price =case" suffix="end,">
                <foreach collection="list" item="cus">
                    <if test="cus.sellPrice!=null">
                        when id=#{cus.id} then #{cus.sellPrice}
                    </if>
                </foreach>
            </trim>
            <trim prefix="card_use_limit =case" suffix="end,">
                <foreach collection="list" item="cus">
                    <if test="cus.cardUseLimit!=null">
                        when id=#{cus.id} then #{cus.cardUseLimit}
                    </if>
                </foreach>
            </trim>

            <trim prefix="valid_time_start =case" suffix="end,">
                <foreach collection="list" item="cus">
                    <if test="cus.validTimeStart!=null">
                        when id=#{cus.id} then #{cus.validTimeStart}
                    </if>
                </foreach>
            </trim>
            <trim prefix="valid_time_end =case" suffix="end,">
                <foreach collection="list" item="cus">
                    <if test="cus.validTimeEnd!=null">
                        when id=#{cus.id} then #{cus.validTimeEnd}
                    </if>
                </foreach>
            </trim>
            <trim prefix="details =case" suffix="end,">
                <foreach collection="list" item="cus">
                    <if test="cus.details!=null">
                        when id=#{cus.id} then #{cus.details}
                    </if>
                </foreach>
            </trim>
            <trim prefix="card_bg =case" suffix="end,">
                <foreach collection="list" item="cus">
                    <if test="cus.cardBg!=null">
                        when id=#{cus.id} then #{cus.cardBg}
                    </if>
                </foreach>
            </trim>
            <trim prefix="add_time =case" suffix="end,">
                <foreach collection="list" item="cus">
                    <if test="cus.addTime!=null">
                        when id=#{cus.id} then #{cus.addTime}
                    </if>
                </foreach>
            </trim>
            <trim prefix="valid_date_type =case" suffix="end,">
                <foreach collection="list" item="cus">
                    <if test="cus.validDateType!=null">
                        when id=#{cus.id} then #{cus.validDateType}
                    </if>
                </foreach>
            </trim>
        </trim>
        <where>
            <foreach collection="list" separator="or" item="cus">
                id = #{cus.id}
            </foreach>
        </where>
    </update>
int updateBatch(List<MembershipCard> list)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值