MyBatis的写法:
<update id="updateWxTopicQs" parameterType="WxTopicQs">
update wx_topic_question
<set>
<if test="topicSurveyGid != null">topic_survey_gid = #{topicSurveyGid,jdbcType=OTHER}::uuid,</if>
<if test="title != null">title = #{title},</if>
<if test="type != null">type = #{type},</if>
<if test="index != null">index = #{index},</if>
</set>
where gid::text = #{gid}
</update>
<insert id="insertWxTopicQs" parameterType="WxTopicQs">
insert into wx_topic_question(
gid,
<trim suffixOverrides=",">
<if test="topicSurveyGid != null ">topic_survey_gid,</if>
<if test="title != null ">title,</if>
<if test="type != null ">type,</if>
<if test="index != null ">index,</if>
update_time
</trim>
) values (
#{gid,jdbcType=OTHER}::uuid, <!-- 添加类型转换 -->
<trim suffixOverrides=",">
<if test="topicSurveyGid != null "> #{topicSurveyGid,jdbcType=OTHER}::uuid,</if>
<if test="title != null ">#{title},</if>
<if test="type != null ">#{type},</if>
<if test="index != null ">#{index},</if>
current_timestamp
</trim>
)
</insert>
解释: