今天遇到一個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坑啊!!!!!!