首页 > 数据库技术 > 详细

MyBatis--动态SQL(set的用法)

时间:2020-06-30 10:58:36      阅读:80      评论:0      收藏:0      [点我收藏+]

技术分享图片

   先修改UserMapper.xml中的selectById方法,代码如下:

 1 <update id="updateById">
 2         update sys_user
 3         <set>
 4         <if test="userName != null and userName !=‘‘">
 5             user_name =#{userName},
 6         </if>
 7         <if test="userPassword != null and userPassword != ‘‘">
 8             user_password =#{userPassword},
 9         </if>
10         <if test="userEmail != null and userEmail != ‘‘">
11             user_email =#{userEmail},
12         </if>
13         <if test="userInfo != null and userInfo != ‘‘">
14             user_info =#{userInfo},
15         </if>
16         <if test="headImg != null">
17             head_img =#{headImg},
18         </if>
19         <if test="createTime != null">
20             create_time =#{createTime},
21         </if>
22             id =#{id}
23         </set>
24         where id =#{id}
25     </update>

注意和在update更新列中使用if标签的区别!!!

   技术分享图片

 

MyBatis--动态SQL(set的用法)

原文:https://www.cnblogs.com/wx60079/p/13211855.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!