MyBatis--動態SQL(set的用法)


   先修改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標簽的區別!!!

   

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM