update neither columns

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

update neither columns

Xinyu HAN

As the example say:
<update id="updateAuthorIfNecessary">>
update Author
<set>
<if test="username != null">username=#{username},</if>
<if test="password != null">password=#{password},</if>
<if test="email != null">email=#{email},</if>
<if test="bio != null">bio=#{bio}</if>
</set>
where id=#{id}
</update>
But if the username, password, email, bio are all null, what will happen? And what's the best practice to handle this scenario?


Actually I expect this update wouldn't be executed when all columns are null.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: update neither columns

Nathan Maves

Take the easy road, do the check before you call the mapper.  If they are all null then don't call the update


On Tue, Jun 6, 2017, 7:04 PM Xinyu HAN <[hidden email]> wrote:

As the example say:
<update id="updateAuthorIfNecessary">>
update Author
<set>
<if test="username != null">username=#{username},</if>
<if test="password != null">password=#{password},</if>
<if test="email != null">email=#{email},</if>
<if test="bio != null">bio=#{bio}</if>
</set>
where id=#{id}
</update>
But if the username, password, email, bio are all null, what will happen? And what's the best practice to handle this scenario?


Actually I expect this update wouldn't be executed when all columns are null.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.