1.带条件的批量更新对象
<update id="updateEvent" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update t_event
<set>
<if test="item.name != null and item.name != ''">name =#{item.name,jdbcType=VARCHAR},</if>
<if test="item.remark != null and item.remark != ''">remark =#{item.remark,jdbcType=VARCHAR},</if>
<if test="item.num!= null">num=#{item.num,jdbcType=INTEGER},</if>
<!--若是允许num=0 在限制条件中需要去掉 num!=''的条件-->
</set>where eventId = #{item.eventId,jdbcType=VARCHAR}
</foreach>
</update>
2.表t_event若只有一列 eventId,并只有一条数据,更新
<update id="updateEvent" parameterType="java.lang.Integer">
update t_event set eventId = #{eventId,jdbcType=INTEGER}
</update>
3.更新event对象一条数据,具有属性name,remark,eventId,level
<update id="update" parameterType="**.Event">
update t_event
<set>
<if test="name != null and name != '' ">user_name = #{name,jdbcType=VARCHAR},</if>
<if test="remark != null and remark != '' ">remark = #{remark,jdbcType=VARCHAR},</if>
<if test="level != null and level != '' ">level = #{level,jdbcType=VARCHAR},</if>
</set>
where eventId = #{eventId,jdbcType=INTEGER}
</update>