[mybatis]动态sql_set_与if结合的动态更新
生活随笔
收集整理的這篇文章主要介紹了
[mybatis]动态sql_set_与if结合的动态更新
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
- 因為sql語句拼裝后,set語句后面可能會多一個逗號,所以要用set標簽
set
<!-- public void updateEmp(Employee employee);--> <update id="updateEmp">update tb1_employee<set><if test = "lastName!=null">last_name = #{lastName},</if><if test="email!=null">email = #{email},</if><if test = "gender!=null">gender =#{gender}</if> </set>where id = #{id}</update>trim(set)
<!-- public void updateEmp(Employee employee);--> <update id="updateEmp">update tb1_employee<trim prefix="set" suffixOverrides=","><if test = "lastName!=null">last_name = #{lastName},</if><if test="email!=null">email = #{email},</if><if test = "gender!=null">gender =#{gender}</if> </trim>where id = #{id}</update>總結(jié)
以上是生活随笔為你收集整理的[mybatis]动态sql_set_与if结合的动态更新的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 玫瑰醋的功效与作用、禁忌和食用方法
- 下一篇: 橙子汁的功效与作用、禁忌和食用方法