八月【sql】

今天遇到一个bug

原代码

    <update id="updateUserInfo" parameterType="java.util.Map">
        UPDATE t_fsans_record T
        SET T.bind_status = #{binding},
        T.bind_time = sysdate(),
        T.phone = #{phone},
        T.bind_form = #{bind_form},
        <if test="referee_phone !=null referee_phone and !=''">
            T.referee_phone = #{referee_phone},
        </if>
        <if test="county !=null and county !=''">
            T.county = #{county}
        </if>
        WHERE T.openid=#{openid} and T.city=#{cityCode}
        and ( T.bind_status <![CDATA[<>]]> 'binding' or T.bind_status is null)
    </update>

如果 if 标签为空,就不会插入,所以

T.bind_form = #{bind_form},

就会多出一个逗号,所以sql执行不通过

修改
    <update id="updateUserInfo" parameterType="java.util.Map">
        UPDATE t_fsans_record T
        SET T.bind_status = #{binding},
        T.bind_time = sysdate(),
        T.phone = #{phone},
        T.bind_form = #{bind_form},
        T.referee_phone = #{referee_phone},
        T.county = #{county}
        
        WHERE T.openid=#{openid} and T.city=#{cityCode}
        and ( T.bind_status <![CDATA[<>]]> 'binding' or T.bind_status is null)
    </update>
有 标签就可以
  • 标签能够自动去掉最后一个逗号

    <update id="updateAuthor" parameterType="com.xwtec.sucai.bean.AuthorBean">
		update t_author
		<set>
			<if test="password!=null">
				password=#{password},
			</if>
			<if test="sex!=null">
				sex=#{sex},
			</if>
			<if test="professionalName!=null">
				professionalName=#{professionalName},
			</if>
		</set>
		<where>
			authorId= #{authorId}
		</where>
    </update>

  • 或者
 <update id="updateUserInfo" parameterType="java.util.Map">
        UPDATE t_fsans_record T
        SET T.bind_status = #{binding},
        T.bind_time = sysdate(),
        T.phone = #{phone},
        T.bind_form = #{bind_form}
        <if test="referee_phone !=null referee_phone and !=''">
            ,T.referee_phone = #{referee_phone}
        </if>
        <if test="county !=null and county !=''">
            ,T.county = #{county}
        </if>
        WHERE T.openid=#{openid} and T.city=#{cityCode}
        and ( T.bind_status <![CDATA[<>]]> 'binding' or T.bind_status is null)
    </update>

T.bind_form = #{bind_form}

后面的逗号去掉,放到标签下。

好TM坑啊!!!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值